【发布时间】:2018-07-13 12:48:17
【问题描述】:
我正在尝试实现某种“视差”效果。
假设我在屏幕顶部有一张图片,高度为:180,下面有一个滚动视图。
初始状态为:
当我向上滚动超过 32 像素时,图像应该“停靠”起来,例如将他的高度设置为 45 像素,并进行动画处理。
最终状态应该是:
在scrollViewDidEndDragging 中,我想将图像停靠在动画上。我使用了以下代码:
self.imageConstraint?.constant = 45.0
UIView.animate(withDuration: 1.0,
delay: 0,
options: [.beginFromCurrentState,
.allowAnimatedContent,
.allowUserInteraction],
animations: {
self.superview?.layoutIfNeeded()
}, completion: { _ in
completion()
})
问题是图像设置为 45 高度,但只有图像,并且保留了一个空白空间(初始高度-最终高度)并且该空间是动画的。 基本上,没有减速,当 scrollDidEndDragging 我想为图像的高度设置动画时,这不能按预期工作。
看起来像这样:
我做错了什么?
【问题讨论】:
标签: ios swift animation imageview constraints