iOS 停止UIView的block动画
iOS停止UIView的block动画的方法
动画执行如下:
UIView.animateWithDuration(animationDuringTime, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { [weak self]() -> Void in
// do animation
animateView?.contentOffset.y = 0
}, completion: { [weak self](finished: Bool) -> Void in
NSLog("completion")
})
如果在动画过程中突然想停止动画,需要执行如下方法
// 这里的 animateView 要为 UIView block animation中进行动画效果的view animateView.layer.removeAllAnimations()
方法执行之后,会UIView block动画会立刻进入completion流程,传入的 finished 值为 false, 可以在代码中通过判断 finished 为 true 或者 false 来区分动画是正常完成还是被停止的。
UIView.animateWithDuration(animationDuringTime, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { [weak self]() -> Void in
// do animation
animateView?.contentOffset.y = 0
}, completion: { [weak self](finished: Bool) -> Void in
if !finished{
NSLog("animation stop")
}else{
NSLog("completion")
}
})

浙公网安备 33010602011771号