[英]How to make an animation repeat a certain amount of times?
出于某种原因,当我点击按钮时,它什么也没做,整个应用程序都关闭了。 有没有人有什么建议? 他们将非常感激。
var start = 1
var timer = Timer()
func test() {
start += 1
}
@IBAction func start(_ sender: Any) {
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(TestViewController.test), userInfo: nil, repeats: true)
while start <= 10 {
UIView.animate(withDuration: 0.1, delay: 0, options: [.repeat, .autoreverse], animations: {
self.buttonLabel.center = CGPoint(x:self.buttonLabel.center.x + 10, y:self.buttonLabel.center.y)
}, completion: nil)
}
}
有一种更好的方法来重复动画,尝试UIView.setAnimationRepeatCount()
@IBAction func start(_ sender: Any) {
UIView.animate(withDuration: 0.1, delay: 0, options: [.repeat], animations: {
UIView.setAnimationRepeatCount(10)
self.buttonLabel.center = CGPoint(x:self.buttonLabel.center.x + 10, y:self.buttonLabel.center.y)
}, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.