I'm porting an older app over to Xcode 7 beta and I'm getting an error on my animations:
Cannot invoke 'animateWithDuration' with an argument list of type '(Double, delay: Double, options: nil, animations: () -> _, completion: nil)'
Here's the code:
UIView.animateWithDuration(0.5, delay: 0.3, options: nil, animations: { self.username.center.x += self.view.bounds.width }, completion: nil)
This works in Xcode 6 so I'm assuming this is an update in Swift. So my question is:
What's the Swift 3 syntax for animateWithDuration?
swift , turn on animation for the button's rotation by adding an animation modifier that begins on changes of the showDetail value. Add another animatable change by making the button larger when the graph is visible. The animation modifier applies to all animatable changes within the views it wraps.
Here's an update with the Swift 3 Syntax:
UIView.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: { self.username.center.x += self.view.bounds.width }, completion: nil)
If you need to add a completion handler just add a closure like so:
UIView.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: { // animation stuff }, completion: { _ in // do stuff once animation is complete })
Old Answer:
It turns out it's a very simple fix, just change options: nil
to options: []
.
Swift 2.2 Syntax:
UIView.animateWithDuration(0.5, delay: 0.3, options: [], animations: { self.username.center.x += self.view.bounds.width }, completion: nil)
Swift 2 got rid of the C-Style comma-delimited list of options in favor of option sets (see: OptionSetType). In my original question, I passed in nil
for my options, which was valid prior to Swift 2. With the updated syntax, we now see an empty option list as an empty set: []
.
An example of animateWithDuration with some options would be this:
UIView.animateWithDuration(0.5, delay: 0.3, options: [.Repeat, .CurveEaseOut, .Autoreverse], animations: { self.username.center.x += self.view.bounds.width }, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With