2017-03-24 34 views
0

這裏是我的代碼:如何重置iOS中的動畫?

override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated) 

    cloud.center.x -= view.bounds.width 
    cloud1.center.x -= view.bounds.width 
    cloud2.center.x -= view.bounds.width 
    cloud3.center.x -= view.bounds.width 
} 

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 

    UIView.animate(withDuration: 12) { 
     self.cloud.center.x += self.view.bounds.width*2 

     UIView.animate(withDuration: 12, delay: 9, options: [], 
         animations: { 
          self.cloud1.center.x += self.view.bounds.width*2 
         }, 
         completion: nil 
     ) 
     UIView.animate(withDuration: 12, delay: 18, options: [], 
         animations: { 
          self.cloud2.center.x += self.view.bounds.width*2 
         }, 
         completion: nil 
     ) 
     UIView.animate(withDuration: 12, delay: 22, options: [], 
         animations: { 
          self.cloud3.center.x += self.view.bounds.width*2 
         }, 
         completion: nil 
     ) 
    } 
} 

我有哪個頁面離開我的動畫這只是停留在一個位置重置一切重做。如何重新設置動畫才能重新播放動畫?

回答

0

您的動畫代碼將您的4個雲視圖向右移動self.view.bounds.width*2,方法是將該數量添加到其中心位置。

要撤銷該更改,只需減去相同的金額即可。

+0

我不想撤銷它,我想動畫做同樣的事情,當我按下按鈕 –

+0

做同樣的事情?反向動畫?如果你想再次做同樣的事情,你必須首先將視圖放回原來的位置。你需要清楚地陳述你的目標。 –