2016-10-05 59 views
0

我不完全確定如何執行一系列動畫。如果我嘗試這個,通常會跳到該函數中的最後一個。Swift動畫 - 執行序列

比方說,我想移動2 UIImageView(並排側)向上300點, 然後2 UILabel(以下UIImageView)300點向上爲好。

然後,我希望標籤從1到10進行計數 - 例如 - 。

最後,一旦標籤已經計爲10,我希望UIImageViewUILabel降低300點。

func moveLabelUP() { 

    label.center = CGPoint(x: label.center.x - 300, y: label.center.y) 

    UILabel.animate(withDuration: 5) { 

     self.label.center = CGPoint(x: self.label.center.x + 300, y: self.label.center.y) 

    func startLabelCountUp(){ 
    timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateLabel), userInfo: nil, repeats: true) 
} 

func updateLabel(){ 
    if self.current < elapsedTime { 
     self.current += 1 

     self.label.text = "\(self.current)" 
    }else{ 
     self.timer.invalidate() 
    } 
} 

我該如何連接這些事件鏈?

如何在每個UILabel計時器開始時應用延遲?

我想UIImageView提高,UILabel計數到10,然後UIImageView降低。這應該重複的第一個的權利的下一個UIImageViewUILabel

+0

你使用約束? –

+0

我現在不使用約束。 我正在製作幾個不同的動畫。一組必須從屏幕開始並出現。 另一隻只能向上移動10點。 –

回答

2

這是我一直在使用它的方式。這只是一個基本的概念,但你會得到一個想法。對於我的情況,我使用常量。

UIView.animate(withDuration: duration, animations: { 

    // Your changes to the UI, eg. moving UIImageView up 300 points 

    }) { (success) in 

     // This executes when animation is completed 
     // Create another animation here. It starts when previous ends 

     UIView.animate(withDuration: duration2, animations: { 

      // Your changes to the UI 

      }, completion: { (success) in 

        // This executes when animation is completed 

      }) 

}) 

還檢查其他框架,可以幫助你,有幾個很好的。我試過Cheetah,它支持鏈接動畫,效果非常好。

只是問你是否有任何問題。