Stworzyłem animację rytmu serca dla Uibutton. Jednak nie ma możliwości zatrzymania tej animacji, ponieważ jest to nieskończona pętla kodu. Po majstrowaniu przy wielu blokach kodu animacji UIView nie udało mi się uzyskać UIViewAnimationOptions.Repeat
, aby produkować to, czego potrzebuję. Gdybym mógł to zrobić, mógłbym po prostu button.layer.removeAllAnimations()
usunąć animacje. Jaki jest sposób, aby napisać to, co pozwala na usunięcie animacji? Myślę, że może to być zegar, ale może to być trochę nieporządne w przypadku wielu animacji.UIButton Heartbeat Animation
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()
}
To jest doskonałe dzięki :) – RichAppz