简体   繁体   中英

Swift animate UIView with multiple options

How does swift handle multiple options when animating UIView? I tried

UIView.animateWithDuration(0.2, delay: 0.0, options: .Repeat | .Autoreverse, animations: {self.alpha = 0.0}, completion: nil)

but seems to confuse the | with a bitwise operator:

Undefined symbols for architecture i386:
 "__TFSsoi1oUSs17_RawOptionSetType_USs21BitwiseOperationsTypeSs9Equatable__FTQ_Q__Q_", referenced from:
      __TFC17TextDrawing10cursorViewW8blinkingSb in cursorView.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am using the latest Xcode version from the AppStore.

Swift 2 :

UIView.animateWithDuration(0.2, delay: 0.0, options: [.Repeat, .Autoreverse], animations: {self.alpha = 0.0}, completion: nil)

Swift 3, 4, 5

UIView.animate(withDuration: 0.2, delay: 0.0, options: [.repeat, .autoreverse], animations: {self.alpha = 0.0}, completion: nil)

The preview answer won't work in nowdays swift. The good answer was given by @mxcl.

If despite all you want to use this form, you have to retrieve the rawValue and rebuild a new UIViewAnimationOptions with an inclusive OR mask.

UIViewAnimationOptions(rawValue:(UIViewAnimationOptions.Autoreverse.rawvalue | UIViewAnimationOptions.Repeat.rawValue))

Swift 3: Tested and ok:

UIView.animate(withDuration: 0.2, delay: 0.0, options: [.repeat, .autoreverse], animations: {
            }, completion: nil)

From the docs it looks like what you are doing is correct?

Have you tried wrapping the options in parentheses?

Either that or put the options into a variable first and try that?

This is working code for me:

        UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.Autoreverse | UIViewAnimationOptions.Repeat, animations: { () -> Void in
            disc.layer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0)
            }) { (success) -> Void in
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM