Ios 如何使动画重复一定的次数?
出于某种原因,当我点击按钮时,它什么也不做,整个应用程序都关闭了。有人有什么建议吗?他们将不胜感激Ios 如何使动画重复一定的次数?,ios,swift,timer,uiviewanimation,Ios,Swift,Timer,Uiviewanimation,出于某种原因,当我点击按钮时,它什么也不做,整个应用程序都关闭了。有人有什么建议吗?他们将不胜感激 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(TestViewC
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)
}
}
var start=1
var timer=timer()
func测试(){
开始+=1
}
@iAction func启动(\发送方:任意){
timer=timer.scheduledTimer(时间间隔:0.1,目标:self,选择器:#选择器(TestViewController.test),userInfo:nil,repeats:true)
在开始时,有更好的方法来重复动画,请尝试UIView.setAnimationRepeatCount()
听起来你的应用程序正在崩溃。请提供有关崩溃的详细信息,包括完整的错误消息,并指出导致崩溃的确切原因。非常感谢你。欢迎你。此外,为了检测应用程序崩溃的原因(从这个问题我假设你的应用程序确实崩溃了)您可以添加一个异常断点,以查看是哪一行代码导致了它。若要执行此操作,请转到断点导航器(屏幕顶部的左侧菜单),按此菜单底部的“+”按钮,然后选择“异常断点”。这将使调试更加容易。Cheers!“setAnimationRepeatCount”在iOS 13.0中已被弃用:请改用基于块的动画API
@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)
}