简体   繁体   中英

UIViewAnimationOptions error migrating from Swift 1 to Swift 2

I just updated Xcode to 7.0.1 and therefore also Swift from Swift 1 to Swift 2.

I got a lot of errors when the update was done and this is one of the problems I can not fix. It would be really nice if you could fix this for me.

The error message says:

Nil is not compatible with expected type UIViewAnimationOption'

UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: nil, animations: ({

}), completion: nil)

Use UIViewAnimationOptions property object for options:

UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

}, completion: nil)

You can use like this:

UIView.animateWithDuration(0, delay: 0, usingSpringWithDamping: 0, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

        }) { (finished: Bool) -> Void in

    }

or

UIView.animateWithDuration(0, delay: 0, usingSpringWithDamping: 0, initialSpringVelocity: 0, options: [UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.Autoreverse], animations: { () -> Void in

        }, completion: nil)

In Swift 2 UIViewAnimationOption is declared as non optional. Therefore it cannot be nil . The equivalent to no options is the generic initializer

... options: UIViewAnimationOption() ...

or a pair of empty brackets

... options: [] ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM