How do I set the UIViewAnimationOptions
to .Repeat
in an UIView
animation block:
UIView.animateWithDuration(0.2, delay:0.2 , options: UIViewAnimationOptions, animations: (() -> Void), completion: (Bool) -> Void)?)
You don't need to use [weak self] in static function UIView. animate() You need to use weak when retain cycle is possible and animations block is not retained by self.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] . It's best to let the OS run your animations; the animation thread does not block the main thread -- only the animation block itself.
Pretty much the same as before:
UIView.animate(withDuration: 0.2, delay: 0.2, options: UIViewAnimationOptions.repeat, animations: {}, completion: nil)
except that you can leave out the full type:
UIView.animate(withDuration: 0.2, delay: 0.2, options: .repeat, animations: {}, completion: nil)
and you can still combine options:
UIView.animate(withDuration: 0.2, delay: 0.2, options: [.repeat, .curveEaseInOut], animations: {}, completion: nil)
UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions.Repeat, animations: {}, completion: nil) UIView.animateWithDuration(0.2, delay: 0.2, options: .Repeat, animations: {}, completion: nil) UIView.animateWithDuration(0.2, delay: 0.2, options: [.Repeat, .CurveEaseInOut], animations: {}, completion: nil)
Most of the Cocoa Touch 'option' sets that were enums prior to Swift 2.0 have now been changed to structs, UIViewAnimationOptions
being one of them.
Whereas UIViewAnimationOptions.Repeat
would previously have been defined as:
(semi-pseudo code)
enum UIViewAnimationOptions { case Repeat }
It is now defined as:
struct UIViewAnimationOption { static var Repeat: UIViewAnimationOption }
Point being, in order to achieve what was achieved prior using bitmasks (.Reverse | .CurveEaseInOut
) you'll now need to place the options in an array, either directly after the options
parameter, or defined in a variable prior to utilising it:
UIView.animateWithDuration(0.2, delay: 0.2, options: [.Repeat, .CurveEaseInOut], animations: {}, completion: nil)
or
let options: UIViewAnimationOptions = [.Repeat, .CurveEaseInOut] UIView.animateWithDuration(0.2, delay: 0.2, options: options, animations: {}, completion: nil)
Please refer to the following answer from user @0x7fffffff for more information: Swift 2.0 - Binary Operator “|” cannot be applied to two UIUserNotificationType operands
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