我正在尝试创建一个animation
,其中视图首先动画下来,然后从超级视图中删除,我的代码如下所示:
UIView.animate(withDuration: 5, delay: 5, options: .allowAnimatedContent, animations: {
NSLog("Animation started")
self.scrollView.setContentOffset(CGPoint(x:0,y:-500), animated: true)
}, completion: {(finished: Bool) in
if finished{
NSLog("Animation stopped")
self.view.removeFromSuperview()
}
})
因为持续时间是5
所以完成后应该在5秒后调用,否则我错了?
在这种情况下,在动画完成之前调用完成并删除视图,动画显然根本没有显示,因为视图已被删除。
以下是NSLog
2017-01-02 17:39:37.649 [1581:26706] Animation started
2017-01-02 17:39:37.652 [1581:26706] Animation stopped
完成在不到一秒的时间内被调用
答案 0 :(得分:3)
尝试将setContentOffset:
函数animated
设置为false
UIView.animate(withDuration: 5, delay: 5, options: .allowAnimatedContent, animations: {
NSLog("Animation started")
self.scrollView.setContentOffset(CGPoint(x:0,y:-500), animated: false)
}, completion: {(finished: Bool) in
if finished{
NSLog("Animation stopped")
self.view.removeFromSuperview()
}
})