animateWithDurationのエラー

animateWithDurationを使っていて
UIView.animateWithDuration(duration, animations)の引数パターン

UIView.animateWithDuration(
    1, // アニメーションの時間
    animations: {() -> Void  in
        // アニメーションする処理
        self.view.frame.origin.x =  0
        return
     }
)

これから動きのオプションを付けようと下記のようにしたら、エラー

UIView.animateWithDuration(
   // アニメーションの時間
    1,
  // アニメーションの変化オプション
  options: UIViewAnimationOptions.CurveEaseOut, 
   // アニメーションする処理
    animations: {() -> Void  in
        self.view.frame.origin.x =  0
        return
     }
)
エラーメッセージ
Cannot invoke 'animateWithDuration' with an argument list of type '(Double, options: UIViewAnimationOptions, animations: () -> Void)'

この場合「引数のリストが違いますよ!」という事らしい。
調べると、optionを入れられるのは、下記のパターン
UIView.animateWithDuration(duration, delay, options , animations, completion)
で、こうしたらコンパイル通りました。

UIView.animateWithDuration(
   // アニメーションの時間
    1,
    //アニメーション開始までの遅延時間
    delay: 0.0,
  // アニメーションの変化オプション
  options: UIViewAnimationOptions.CurveEaseOut, 
   // アニメーションする処理
    animations: {() -> Void  in
        self.view.frame.origin.x =  0
        return
     },
     // アニメーション終了後の処理
    completion: {(finished: Bool) -> Void in
        //do something
    }
)

コメント