2016-05-12 15 views
-1

アニメーションの終了後にセグを実行しようとしています。アニメーションの終了後にセグを実行する

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

    imageViewAnimated.startAnimating() 


    if label.center != CGPoint(x:50, y:10) { 

     UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: {() -> Void in 
      self.label.center = self.view.center 

      }, completion: nil) 

     UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: {() -> Void in 
      //    self.label.center = CGPoint(x: 50,y:300) 
      self.label.alpha = 0.0 

      }, completion: nil) 
    } 

    if label.alpha == 0.0 { 
     UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: {() -> Void in 

      self.performSegueWithIdentifier("backSegue", sender: self) 

      }, completion: nil) 
    } 
} 

だから基本的に私は下に移動し、フェードアウトのラベル(第1および第2 animateWithDuration)が、その後、私はラベルがフェードアウトされた後にセグエが発生します:ここで私はviewDidAppearを持っているコードがありますもう一方のアニメーションが行われます。現在、セグエは起きていますが、すぐにやりますが、どれだけ遅れても待ちません。

+0

関数が完了した後にアクションを実行する場合は、「完了」ブロックでコードをコーディングする必要があります。メソッドが終了したら完了ブロックが呼び出されます。 – Bharath

+0

答えを更新しました –

答えて

1

を終了した後、完了ブロックが呼び出されます。

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

    imageViewAnimated.startAnimating() 

    if label.center != CGPoint(x:50, y:10) { 
     UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: {() -> Void in 
      self.label.center = self.view.center 
     }, completion: nil) 

     UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: {() -> Void in 
      //    self.label.center = CGPoint(x: 50,y:300) 
      self.label.alpha = 0.0 
     }, completion: { finished in 
      self.performSegueWithIdentifier("backSegue", sender: self) 
     }) 
    } 
} 
+0

ありがとうございます!私はなぜそれがしばらく(セグを行うには約15秒)かかるのか分かりません。それはちょうど私の遅いコンピュータかもしれない。 – Bailey

0

完了後にセグコードを実行してください。あなたはそれを "Completion"ブロックにコーディングする必要があります。この方法は、あなたが間違った場所にセグエを呼び出しているアニメーション

UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: {() -> Void in 

       //if you perform segue here if will perform with animation 

       }, completion: { finished in 

     //if you perform segue it will perform after it finish animating. 

    self.performSegueWithIdentifier("backSegue", sender: self) 


    }) 
0

アニメーションブロックの補完ハンドラ部分にナビゲーションコードを書くことができます。補完ハンドラはアニメーションの完了後に起動するためです。

[UIView animateWithDuration:0.25 animations:^{ 
    //Animation changes 
} completion:^(BOOL finished) { 
    //Navigation 
}]; 
+0

質問にはObjective-CではなくSwiftというタグが付いていることに注意してください。 – rmaddy

関連する問題