【发布时间】:2016-12-30 13:57:42
【问题描述】:
我正在尝试在我的应用中实现以下功能:
- 具有图像视图和作为子视图的视图的滚动视图。
当我从滚动视图的顶部向下拖动时,图像视图的高度会增加,在宽高比填充模式下,给人一种缩放的感觉。
当我放手时,图像恢复到原来的高度。
所以基本上,我正在尝试复制 Facebook 应用的即时文章页面。
问题是我无法将图像视图恢复为原始大小。它似乎总是猛地回到它。 UIView.animateWithDuration() 由于某种原因在这里不起作用:/
这是我的代码: (imageHeight 是 UIImageView 的高度约束的 IBOutlet)
func scrollViewDidScroll(scrollView: UIScrollView) {
let y = self.scrollView.contentOffset.y
if y < 0 && self.imageHeight.constant < 500
{
self.imageHeight.constant += (-1*y)*0.5;
}
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
self.stoppedScrolling()
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate
{
self.stoppedScrolling()
}
}
func stoppedScrolling()
{
UIView.animateWithDuration(1) {
self.imageHeight.constant = 180
}
}
Here's a gif of the result 此外,它没有显示在 gif 中,但在结束触摸和调整大小之间有半秒的延迟
【问题讨论】:
标签: ios swift uiscrollview uiimageview