ios - 无法快速停止 UIView 动画

标签 ios swift uiviewanimation

这是我的动画代码:

UIView.animate(withDuration: 1, delay: 1, options: [.repeat], animations: {
        self.micButtonOuterRing?.frame = CGRect(x: (self.originalOuterRingFrame?.origin.x)! - 30, y: (self.originalOuterRingFrame?.origin.y)! - 30, width: (self.originalOuterRingFrame?.width)! + 60, height: (self.originalOuterRingFrame?.height)! + 60)
        self.micButtonOuterRing?.alpha = 0
        self.micButtonOuterRing?.layer.cornerRadius = (self.micButtonOuterRing?.frame.width)! / 2
    }, completion: { _ in
        self.micButtonOuterRing?.frame = self.originalOuterRingFrame!
        self.micButtonOuterRing?.alpha = 1
    })

我试图在按下按钮时停止它,所以我运行以下命令:

@IBAction func micButtonPressed(_ sender: Any) {

    micButtonOuterRing?.layer.removeAllAnimations()

}

但是动画还在继续。我知道 micButtonPressed 函数有效,因为我添加了打印语句并且它有效。有人可以帮忙吗?

最佳答案

使用UIPropertyAnimator反而;它旨在让您暂停,stop , reverse 等,语法几乎与旧的 UIViewAnimation 方法完全相同。

关于ios - 无法快速停止 UIView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47481287/

相关文章:

ios - 如何以反 L 形为图像制作动画

ios - 核心 Spotlight API - 搜索结果中的 kUTTypeAudio 播放按钮

ios - Objective-c:从具有范围的集合(NSArray)中获取最短范围的最有效方法

ios - 如何从 IOS 的启动屏幕检查 NsUserDefaults?

ios - 使用 UICollectionView 调整 UICollectionViewCell 的大小

objective-c - 如何翻转单个 UIView(不翻转父 View )

ios - UITableView:如何通过长按更改自定义单元格中的 UIView 状态?

ios - 如何在 objective-c 中为我的一系列任务创建队列

ios - 无法在 Objective-C .m 文件中调用 Swift 方法

ios - UIProgressView 快速崩溃消息是 Thread 6 : Fatal error: Unexpectedly found nil while unwrapping an Optional value