1
私はSwiftを学びたいと思っています。Swift 3. UIView.animateを終了します
func getRandomColor(){
let red = Float((arc4random() % 256))/255.0
let green = Float((arc4random() % 256))/255.0
let blue = Float((arc4random() % 256))/255.0
let alpha = Float(1.0)
colours = UIColor(colorLiteralRed: red, green: green, blue: blue, alpha: alpha)
UIView.animate(withDuration: 2, delay: 1.0, options:[UIViewAnimationOptions.repeat, UIViewAnimationOptions.autoreverse], animations: {
self.view.backgroundColor = self.colours}, completion:nil)
}
func updateTimer(){
if seconds! == 0 {
timer.invalidate()
isTimerRunning = false
}
else {
seconds! -= 1
timerLabel.text = timeString(time: TimeInterval(seconds!))
}
if seconds! < 55 {
getRandomColor()
}
}
秒が0の場合、タイマーは停止しますが、アニメーションは続行されます。タイマー停止時にアニメーションを停止するにはどうすればいいですか?あなたに
UIViewAnimationOptions.repeat updateTimer()が実行されるたびにその関数を実行しているので、再度繰り返す必要はありません。 – Farini