ios - 取消 UIview.animation 与用户交互

标签 ios

我们有一个像这样的水平动画:

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)
})

我们这样做是为了让整个 View 内容向左移动一点(重复两次),以向用户表明他们可以与我们的水平轮播(使用 Collection View 构建)进行交互。

但是,如果用户与 View 交互,有没有办法取消这个动画?

有一个类似的问题:UIView animations canceling any touch input? 。但它不一样。我们感兴趣的不仅是允许用户交互,而且还立即取消动画,因为我们知道用户已经理解了 UI。

最佳答案

如果只是取消动画,只需终止所有动画,如下所示:

     self.collectionView.layer.removeAllAnimations()

这不是暂停,而是运行完成 block 。

关于ios - 取消 UIview.animation 与用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53436131/

相关文章:

ios - 是否为AVAssetReaderAudioMixOutput指定基于软件的编解码器?

ios - Xcode 的自动拼写检查器

ios 无法使用 graph api 获取 facebook 的好友列表

ios - 在 Spritekit 中添加音效

ios - UIFontMetrics : scaled font size calculation

ios - MFMailComposeViewController 不关闭

ios - 使 UISearchBar 不像在联系人应用程序中那样滚动

ios - Objective C-如何在后退按钮上显示viewController的简称

iOS 应用程序 - 在 GridView 中显示来自 JSON URL 列表的图像。

ios - 我们可以更改 UITableView 中当前行的高度吗?