icaksama
icaksama

Reputation: 772

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 ?

Upvotes: 3

Views: 987

Answers (2)

Yuvaraj M
Yuvaraj M

Reputation: 340

You can use animation option like this:

Swift 2

UIView.animateWithDuration(0.2, delay: 0.0, options: [.Repeat, 
.Autoreverse, .CurveLinear, .CurveEaseOut, .CurveEaseInOut,
.TransitionCurlUp, .TransitionCurlDown, 
.TransitionFlipFromBottom,.TransitionFlipFromLeft,.TransitionFlipFromRight, 
.BeginFromCurrentState, .CurveEaseIn], animations: {}, completion: nil)

Swift 3, 4, 5

UIView.animate(withDuration: 0.2, delay: 0.0, options: [.repeat, 
.autoreverse, .curveLinear, .curveEaseOut, .curveEaseInOut,
.transitionCurlUp, .transitionCurlDown, 
.transitionFlipFromBottom,.transitionFlipFromLeft,.transitionFlipFromRight, 
.beginFromCurrentState, .curveEaseIn], animations: {}, completion: nil)

Upvotes: 0

Sachin Vas
Sachin Vas

Reputation: 1767

    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.

Upvotes: 5

Related Questions