icaksama icaksama - 1 year ago 89
Swift Question

iOS Swift - Cannot Change Animation Options with Array [UIViewAnimationOptions]

I have some problem about animation options with

array
in Swift 2. I can add multiple options in
array
like this :
[.Repeat, UIViewAnimationOptions.Autoreverse]
and this is if I add in animation function (first example) :

UIView.animateWithDuration(1, delay: 0, options: [.Repeat, UIViewAnimationOptions.Autoreverse], animations: {

}) { (true) in

}


But I cannot add animation options in
array
like this (second example) :

var animationOptions = [UIViewAnimationOptions]()
animationOptions.append(UIViewAnimationOptions.Repeat)
animationOptions.append(UIViewAnimationOptions.Autoreverse)
UIView.animateWithDuration(1, delay: 0, options: animationOptions, animations: {

}) { (true) in

}


Can someone help me make animation options in array like second example ?

Answer Source
    var animationOptions:UIViewAnimationOptions = .repeat
    animationOptions.insert(.autoreverse)
    UIView.animate(withDuration: 0.1, delay: 0.1, options: animationOptions, animations: {

    }) { (success:Bool) in

    }

You need to use the insert from the SetAlgebra Protocol, which the OptionSet conforms to. In the question you are using the Array Object instead of the UIViewAnimationOptions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download