gpt4 book ai didi

ios - 如何让动画重复一定次数?

转载 作者:搜寻专家 更新时间:2023-11-01 06:33:19 24 4
gpt4 key购买 nike

出于某种原因,当我点击按钮时,它什么也没做,整个应用程序都关闭了。有没有人有什么建议?他们将不胜感激。

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)
}

关于ios - 如何让动画重复一定次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44742680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com