私はUIButtonのハートビートアニメーションを作成しました。しかし、無限のコードループであるため、このアニメーションを停止する方法はありません。多数のUIViewアニメーションコードブロックを修正した後、私は必要なものを生成するためにUIViewAnimationOptions.Repeat
を得ることができませんでした。もし私がそれを行うことができたら、私は単にbutton.layer.removeAllAnimations()
アニメーションを削除することができます。これを書いてアニメーションを削除する方法は何ですか?私はおそらくタイマーを考えていますが、それは多種のアニメーションが進行しているので面倒です。UIButtonハートビートアニメーション
func heartBeatAnimation(button: UIButton) {
button.userInteractionEnabled = true
button.enabled = true
func animation1() {
UIView.animateWithDuration(0.5, delay: 0.0, options: [], animations: {() -> Void in
button.transform = CGAffineTransformMakeScale(2.0, 2.0)
button.transform = CGAffineTransformIdentity
}, completion: nil)
UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {() -> Void in
button.transform = CGAffineTransformMakeScale(2.0, 2.0)
button.transform = CGAffineTransformIdentity
}) { (Bool) -> Void in
delay(2.0, closure: {() ->() in
animation2()
})
}
}
func animation2() {
UIView.animateWithDuration(0.5, delay: 0.0, options: [], animations: {() -> Void in
button.transform = CGAffineTransformMakeScale(2.0, 2.0)
button.transform = CGAffineTransformIdentity
}, completion: nil)
UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {() -> Void in
button.transform = CGAffineTransformMakeScale(2.0, 2.0)
button.transform = CGAffineTransformIdentity
}) { (Bool) -> Void in
delay(2.0, closure: {() ->() in
animation1()
})
}
}
animation1()
}
これは完璧な感謝です:) – RichAppz