0
我有一個標籤,最初位於屏幕的中心。它目前從屏幕的中心向右端過渡,然後自動反向回到它的位置。我想讓它開始另一個animateWithDuration,以便它從中心返回到屏幕的左側位置,然後自動返回到該位置,然後從那裏繼續循環。animateWithDuration一個接一個
我已經嘗試併成功完成了上半部分的工作,但我不確定如何繼續到第二部分,它開始中心→左邊的過渡和循環。
雨燕2.0代碼:
func animateRight()
{
UIView.animateWithDuration(1.0, delay: 0.0, options: [ .Autoreverse, .CurveEaseInOut], animations: {
label.center.x = self.view.frame.width/2
}, completion: { finished in
if finished {
label.frame.origin.x = 0.0
animateLeft()
}
})
}
func animateLeft()
{
UIView.animateWithDuration(1.0, delay: 0.0, options: [ .Autoreverse, .CurveEaseInOut], animations: {
label.frame.origin.x = (self.view.frame.width/2) * -1
}, completion: { finished in
if finished {
label.center.x = self.view.frame.width/2
animateRight()
}
})
}
// Start process
animateRight()
這很好!我已經更進了一步,但它運作不正確。我對整個循環持續不斷,因爲它只是一個動畫,可以無限重複視覺效果。我更新了我的代碼,目前它運行animateRight()並順序運行animationLeft();但animationLeft()循環並且從不按預期調用animateRight()。 – theflarenet
我已經更新了代碼。因此,現在右側的動畫不會使用.Autoreverse,但會在右側結束。然後離開動畫被叫做.Autoreverse和。重複 –
優秀!謝謝! – theflarenet