これを試してみてください:
UIView.animateWithDuration(1.0, animations: {() -> Void in
self.view.backgroundColor = UIColor.blackColor()
}) { (Bool) -> Void in
UIView.animateWithDuration(1.0, animations: {() -> Void in
self.view.backgroundColor = UIColor.greenColor()
}, completion: { (Bool) -> Void in
UIView.animateWithDuration(1.0, animations: {() -> Void in
self.view.backgroundColor = UIColor.grayColor()
}, completion: { (Bool) -> Void in
UIView.animateWithDuration(1.0, animations: {() -> Void in
self.view.backgroundColor = UIColor.redColor()
}, completion:nil)
})
})
}
あなたが連続繰り返しアニメーションをしたい場合は、これを試してみる:コードの下
UIView.animateWithDuration(2, delay: 0.0, options:[UIViewAnimationOptions.Repeat, UIViewAnimationOptions.Autoreverse], animations: {
self.view.backgroundColor = UIColor.blackColor()
self.view.backgroundColor = UIColor.greenColor()
self.view.backgroundColor = UIColor.grayColor()
self.view.backgroundColor = UIColor.redColor()
}, completion: nil)
私の解決策を試してください。アニメーション補完ブロックを使用することは、タイマーを実行するよりも常に優れています。 – Abhinav