// Options
// OC中的选项使用的NS_OPTIONS定义选项类枚举,就是可以|的
/*
typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions){
UIViewAnimationOptionLayoutSUbviews = 1 << 0,
UIViewAnimationOptionAllowUserInteracion = 1 << 1,
...
}
*/
//在Swift中NS_OPTIONS被改为了满足OptionSetType协议的struct类型,以及一组静态的get属性
/*
public struct UIViewAnimationOptions : OptionSet {
public init(rawValue: UInt)
public static var layoutSubviews: UIViewAnimationOptions { get }
public static var allowUserInteraction: UIViewAnimationOptions { get } // turn on user interaction while animating
...
}
*/
// UIView动画就变为了
UIView.animate(withDuration:0.3,
delay:0,
options: [.curveEaseIn, .allowUserInteraction],
animations: {},
completion:nil)
//并且OptionSet实现了SetAlgebra这个协议,我们可以对两个集合尽心各种集合运算,包括并集,交集。对于不需要输入的情况,直接一个[]空集合
//我们可以自己简历一个Options
structMyOption :OptionSet{
letrawValue:UInt
staticletnone =MyOption(rawValue:0)
staticletoption1 =MyOption(rawValue:1)
staticletoption2 =MyOption(rawValue:1<<1)
staticletoption3 =MyOption(rawValue:1<<2)
// ...
}
// NS_ENUM定义普通枚举在Swift中使用enum类型来对应
/*
public enum UIViewTintAdjustmentMode : Int {
case automatic
case normal
case dimmed
}
*/