-1
我想我的viewController中的imageView“脉动”,这意味着变大,然后再变小,重复,直到“开始”按钮被按下。问题是,每次我在viewDidLoad()中使用repeat-while循环调用该函数时,无论出于何种原因它都有一个断点。重复while循环不起作用 - 为什么?
这是()我viewDidLoad中的一部分:
repeat {
pulsate()
} while hasStarted == false
当我按下启动按钮,hasStarted成为真正的,它应该停止跳动。但它甚至不启动该功能,它立即调用一个错误。问题在哪里?
这里是我的搏动() - 函数
func pulsate()
{
frameOR = imageView.frame
frameNext = CGRect(x: imageView.frame.midX - 35, y: imageView.frame.midY - 35, width: 80, height: 80)
let frameVDL = CGRect(x: imageView.frame.midX - 150, y: imageView.frame.midY - 150, width: 300, height: 300)
if start == false
{
UIView.animate(withDuration: 2, animations: {
self.imageView.frame = frameVDL
}) { (finished) in
UIView.animate(withDuration: 2, animations: {
self.imageView.frame = self.frameOR
}, completion: nil)
}
}
}
感谢您的帮助!祝你有美好的一天!
有什么错误? –
您正在阻止主线程。在程序控制返回到主事件循环之前,没有按钮(或任何其他)的UI操作方法将被执行。 –