【发布时间】:2019-06-24 11:30:43
【问题描述】:
我有 animateButtons() 函数,只有在动画完成时我才需要设置完成处理程序。问题是在animateButtons() 中,我只能在imageView.startAnimating() 之后设置完成处理程序,因此整个时间都会受到影响,因为它的完成用于启动其他动画。我在另一篇文章中读到了同样的问题,我应该设置一个 NSTimer 来设置完成处理程序,正如我真正想到的那样,但我真的不知道该怎么做。我已将 NSTimer 设置为调用 setCompletion() 函数,但如何将其设置为调用 animateButtons() 完成处理程序?
你能指出我正确的方向吗?
这是函数和选择器函数:
static func animateButtons(completed: @escaping(Bool) ->(), imageView: UIImageView, images: [UIImage]) {
imageView.animationImages = images
imageView.animationDuration = 1.0 // check duration
imageView.animationRepeatCount = 1
imageView.startAnimating()
_ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(setCompletion), userInfo: nil, repeats: false)
// completed(true)
}
@objc func setCompletion() {
}
【问题讨论】:
标签: ios swift completionhandler