我有一个函数,它开始播放一个异步运行的动画(在后台)。使用完成处理程序(见下文),无限期地调用此动画。是否有一种方法在按下另一个按钮时关闭此函数?
以下是我的代码:
func showAnimation() {
UIView.animate(withDuration: 1, animations: {
animate1(imageView: self.Anime, images: self.animation1)
}, completion: { (true) in
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.showAnimation() // replay first showAnimation
}
})
}
然后在按下另一个按钮时,我们关闭上述函数。
showAnimation().stop();
谢谢