我们有一个像这样的水平动画:
UIView.animate(
withDuration: 400.millisecond,
delay: 600.milliseconds,
options: [.autoreverse, .beginFromCurrentState, .allowUserInteraction],
animations: {
UIView.setAnimationRepeatCount(5)
self.collectionView.transform = CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: -30, ty: 0)
}, completion: { _ in
self.collectionView.transform = CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0)
})我们这样做是为了让整个视图内容向左移动一点(重复两次),以向用户表明他们可以与我们的水平轮播(使用集合视图构建)进行交互。
但是,如果用户已经与视图进行了交互,是否有方法可以取消此动画?
还有一个类似的问题被问到:UIView animations canceling any touch input?。但这是不一样的。我们感兴趣的不仅是允许用户交互,而且还可以立即取消动画,因为我们知道用户已经理解了UI。
发布于 2018-11-23 02:20:06
如果只是取消动画,就像这样终止所有动画:
self.collectionView.layer.removeAllAnimations()它不是暂停,而是运行完成块。
https://stackoverflow.com/questions/53436131
复制相似问题