2016-05-14 6 views
1

私は、ユーザーがログインボタンをタップした後に落ちるページ上のオブジェクトである5つのアニメーションを持っています。私は、次のそれぞれに0.3増分の遅延を入れました。私は、このコードを書くためのよりクリーンで効率的な方法があるのだろうかと思っていました。アニメーションを完成させてアニメーションを組み合わせる

func loggedInAnimate1(){ 

    UIView.animateWithDuration(2, 
           delay: 0.0, 
           options: .CurveEaseIn, 
           animations: { 
           self.newUser.center.y += self.view.bounds.width 

     }, completion: nil) 

} 

func loggedInAnimate2(){ 

    UIView.animateWithDuration(2, 
           delay: 0.3, 
           options: .CurveEaseIn, 
           animations: { 
           self.loginButton.center.y += self.view.bounds.width 

     }, completion: nil) 

} 

func loggedInAnimate3(){ 

    UIView.animateWithDuration(2, 
           delay: 0.6, 
           options: .CurveEaseIn, 
           animations: { 
           self.loginPasswordTextField.center.y += self.view.bounds.width 

     }, completion: nil) 

} 

func loggedInAnimate4(){ 

    UIView.animateWithDuration(2, 
           delay: 0.9, 
           options: .CurveEaseIn, 
           animations: { 
           self.loginEmailTextField.center.y += self.view.bounds.width 

     }, completion: nil) 

} 

func loggedInAnimate5(){ 

    UIView.animateWithDuration(3, 
           delay: 1.2, 
           options: .CurveEaseIn, 
           animations: { 
           self.logo.center.y += self.view.bounds.height 

     }, completion: nil) 

} 

最後にもう1つの関数を呼び出す...これはすべて可能ですか?ありがとう

答えて

2

完了クロージャを使用して次のアニメーションを開始できます。そうすれば、遅延を使う必要はなく、アニメーションを入れ子にすることができます。

UIView.animateWithDuration(2, delay: 0, options: .CurveEaseIn, animations: { 
    self.newUser.center.y += self.view.bounds.width 
}, completion: { _ in 
    UIView.animateWithDuration(2, delay: 0, options: .CurveEaseIn, animations: { 
     self.loginButton.center.y += self.view.bounds.width 
    }, completion: { _ in 
     // And so on... 
    }) 
}) 
関連する問題