如何让动画重复一定次数?
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)
}
出于某种原因,当我点击按钮时,它什么也没做,整个应用程序都关闭了。有没有人有什么建议?他们将不胜感激。
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)
}