Search code examples
uiviewswift2animatewithduration

Setting options in animateWithDuration in Swift 2


I am animating a textfield with the following code:

UIView.animateWithDuration(0.5, delay: 0.4,
        options: .Repeat | .Autoreverse | .CurveEaseOut, animations: {
            self.password.center.x += self.view.bounds.width
        }, completion: nil)

I get the error Could not find member 'Repeat'

The code only works if I set only one option. Why is it not letting me set multiple options?


Solution

  • The syntax for combining OptionSetType has changed, you will be able to do it like this:

    UIView.animateWithDuration(0.5, delay: 0.4,
        options: [.Repeat, .CurveEaseOut, .Autoreverse], animations: {
            self.password.center.x += self.view.bounds.width
        }, completion: nil)