1
votes

I can't figure out the proper syntax for calling the UIView method animateWithDuration. I've found some examples where others have had similar problems, and the solutions for those don't seem to work in the most recent version of Swift, 2.0. I'm getting this generic error:

Cannot invoke 'animateWithDuration' with an argument list of type '(duration: Double, delay: Double, options: UIViewAnimationTransition, animations: ()->_, completion: nil)'

I believe I've narrowed the problem down to the "animations:" parameter. Here is my code:

UIView.animateWithDuration(duration: 0.2, 
    delay: 0.0, 
    options: UIViewAnimationTransition.FlipFromLeft, 
    animations: {
        // Hide image here
    }, 
    completion: nil)

Any suggestions would be appreciated, thanks.

2

2 Answers

1
votes

Try this:

  UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
        }, completion: nil)

Xcode code completion usually helps figure these things out. :-)

Also, for the animation options you're using a constant meant for something else. Use UIViewAnimationOptions instead.

0
votes

Get rid of the duration label on the first parameter:

UIView.animateWithDuration(0.2, 
    delay: 0.0, 
    options: UIViewAnimationTransition.FlipFromLeft, 
    animations: {
        // Hide image here
    }, 
    completion: nil)