This post描述了如何在Objective-C中链接重复的UIView动画。但是,它需要performSelector
,这似乎在Swift中不可用。
如何在Swift中链接重复的UIView动画?目标是创建一个动画来摇动/摆动UIView。
答案 0 :(得分:0)
怎么样:
var wobble = true
func wobbleLeft() {
if !wobble {
return
}
UIView.animateWithDuration(0.5, animations: { () -> Void in
// Animate wobble to left
}) { (finished) -> Void in
self.wobbleRight()
}
}
func wobbleRight() {
if !wobble {
return
}
UIView.animateWithDuration(0.5, animations: { () -> Void in
// Animate wobble to right
}) { (finished) -> Void in
self.wobbleLeft()
}
}
首先致电wobbleLeft()
,然后在完成后致电wobbleRight()
。要停止摆动,只需设置wobble = false