【发布时间】:2017-04-21 12:05:57
【问题描述】:
我正在制作包含 ImageView 和 Label 的视图动画。 请参见图 1。当在 tableView 上滚动完成时,我正在尝试为 upperView 设置动画。最终的结果应该如图 2 所示。其中 imageView 的高度和宽度减小了,并且位于左角,并且在 imageView 前面具有最小高度和标签。动画工作正常,imageView 从原始位置顺利到达最终位置,Label 也是如此。但是根据动画,upperView 不起作用。
我尝试了使用 upperViews 高度约束和框架。
如果我用它的高度约束来改变它,它会很快到达它的最终位置。
如果我使用 upperView.frame.size.height 给出高度,那么视图会上升,但表格视图仍保留在原位。
这是我尝试过的
func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.y > 0
{
UIView.animateWithDuration(1.5, delay: 0.0, options: .CurveEaseOut, animations:
{
self.imageView.frame = CGRect(x: 5.0, y: 0.0, width: 30, height: 40)
}, completion: { finished in
UIView.animateWithDuration(1.5, delay: 1.0, options: UIViewAnimationOptions.AllowUserInteraction,animations: {
self.selectedProgramNameLabel.center = CGPoint(x: self.selectedProgramNameLabel.center.x, y: self.imageView.center.y)
}, completion: { finished in
UIView.animateWithDuration(1.5, delay: 2.0, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.upperViewHeightConstraint.constant = 50
}, completion: { finished in
})
})
})
}
else if scrollView.contentOffset.y == 0
{
UIView.animateWithDuration(1.5, delay: 0.0, options: .CurveEaseOut, animations:
{
self.selectedProgramNameLabel.center = CGPoint(x: self.selectedProgramNameLabel.center.x, y: self.imageView.center.y + self.imageView.frame.height - 45)
}, completion: { finished in
UIView.animateWithDuration(1.5, delay: 0.0, options: UIViewAnimationOptions.AllowUserInteraction,animations: {
self.imageView.frame = CGRect(x: self.upperView.frame.origin.x, y: self.upperView.frame.origin.y, width: 100.0, height: 134)
}, completion: { finished in
UIView.animateWithDuration(1.5, delay: 1.0, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
}, completion: { finished in
})
})
})
}
TIA。
【问题讨论】: