使用Swift的UIViewanimation选项

如何将UIViewAnimationOptions设置为UIViewanimation块中的.Repeat

 UIView.animateWithDuration(0.2, delay:0.2 , options: UIViewAnimationOptions, animations: (() -> Void), completion: (Bool) -> Void)?) 

2 Solutions collect form web for “使用Swift的UIViewanimation选项”

Swift 3

和以前几乎一样:

 UIView.animate(withDuration: 0.2, delay: 0.2, options: UIViewAnimationOptions.repeat, animations: {}, completion: nil) 

除了你可以省略完整的types:

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

你仍然可以结合选项:

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

Swift 2

 UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions.Repeat, animations: {}, completion: nil) UIView.animateWithDuration(0.2, delay: 0.2, options: .Repeat, animations: {}, completion: nil) UIView.animateWithDuration(0.2, delay: 0.2, options: [.Repeat, .CurveEaseInOut], animations: {}, completion: nil) 

大多数在Swift 2.0之前是枚举的Cocoa Touch'option'集合现在已经被改为结构体, UIViewAnimationOptions就是其中之一。

UIViewAnimationOptions.Repeat以前被定义为:

(半伪码)

 enum UIViewAnimationOptions { case Repeat } 

现在定义为:

 struct UIViewAnimationOption { static var Repeat: UIViewAnimationOption } 

重点是,为了实现之前使用位掩码(.Reverse .Reverse | .CurveEaseInOut )所实现的function,您现在需要将选项放在数组中,或者直接放在options参数之后,或者在使用之前定义在variables中:

 UIView.animateWithDuration(0.2, delay: 0.2, options: [.Repeat, .CurveEaseInOut], animations: {}, completion: nil) 

要么

 let options: UIViewAnimationOptions = [.Repeat, .CurveEaseInOut] UIView.animateWithDuration(0.2, delay: 0.2, options: options, animations: {}, completion: nil) 

有关更多信息,请参阅user @ 0x7fffffff中的以下答案: Swift 2.0 – 二元运算符“|”不能应用于两个UIUserNotificationType操作数