Swift为UIView设置了多个选项

时间:2014-10-07 07:37:18

标签: ios uiview swift xcode6 uiviewanimation

在动画UIView时,swift如何处理多个选项?我试过了

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

但似乎将|与按位运算符混淆:

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)

我正在使用AppStore中的最新Xcode版本。

5 个答案:

答案 0 :(得分:31)

Swift 2

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

Swift 3

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

答案 1 :(得分:2)

预览答案在现今的swift中无效。 @mxcl给出了很好的答案。

如果您只想使用此表单,则必须检索rawValue并使用包含OR的掩码重建新的UIViewAnimationOptions。

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

答案 2 :(得分:1)

斯威夫特3: 经过测试和确定:

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

答案 3 :(得分:0)

来自the docs看起来你正在做的事情是正确的吗?

您是否尝试将选项括在括号中?

要么首先将选项放入变量并尝试?

答案 4 :(得分:-2)

这是我的工作代码:

        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
        }