我有一个我最近发现不能正常工作的动画
//time is a variable used in my code
UIView.animate(withDuration: time, delay: 0, options: [.curveLinear, .allowUserInteraction], animations: {
//this class is ofType UIScrollView
self.setContentOffset(CGPoint(x: self.contentSize.width-self.frame.width, y: 0), animated: false)
//Completion Handler
}, completion: { finished in
//It's always true, not sure a way to fix this
if(finished ) {
但是,稍后在我的代码中,我有一个方法来删除某些动画,特别是从这个scrollView。
self.layer.removeAllAnimations()
它被调用,我认为它是假设做出上述
if(finished ) { //Here
返回false,因此它不应该进入完成。但是,完成总是如此。无论我取消这个动画,继续动画,对动画做什么都不重要,完成处理程序总是如此。关于此事的任何提示?
答案 0 :(得分:2)
您对setContentOffset的调用指定了animated:false,如果这是您要更改的唯一属性,则没有实际的动画,因此对.animate(...)的调用将始终以值true完成。如果您使用animated:true设置此属性(或另一个属性)并且您的持续时间太短而无法完成动画,那么它可能会以参数的false值结束。