Я создал анимацию сердечного ритма для UIButton. Однако нет возможности остановить эту анимацию, поскольку это бесконечный цикл кода. После обработки многочисленными блоками кода анимации UIView мне не удалось получить UIViewAnimationOptions.Repeat
, чтобы создать то, что мне нужно. Если бы я мог сделать это, я мог бы просто button.layer.removeAllAnimations()
удалить анимацию. Каков способ написать это, что позволяет удалить анимацию? Я думаю, что возможно таймер, но это может быть довольно грязно с несколькими анимациями.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()
}
Это идеальное спасибо :) – RichAppz