OC的位移枚举的区分
//位移枚举
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
//普通枚举
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
};
OC位移枚举的使用
OC里面位移枚举的使用一般用按位或运算符,也就是|
运算符。
//OC里位移枚举的定义
enum UIViewAnimationOptions option = UIViewAnimationOptionRepeat | UIViewAnimationOptionLayoutSubviews;
//OC里普通枚举的定义
enum UIViewAnimationTransition option = UIViewAnimationTransitionFlipFromLeft;
swift的位移枚举的区分
//位移枚举
public struct UIViewAutoresizing : OptionSetType {
public init(rawValue: UInt)
public static var None: UIViewAutoresizing { get }
public static var FlexibleLeftMargin: UIViewAutoresizing { get }
public static var FlexibleWidth: UIViewAutoresizing { get }
public static var FlexibleRightMargin: UIViewAutoresizing { get }
public static var FlexibleTopMargin: UIViewAutoresizing { get }
public static var FlexibleHeight: UIViewAutoresizing { get }
public static var FlexibleBottomMargin: UIViewAutoresizing { get }
}
//普通枚举
public enum UIViewAnimationTransition : Int {
case None
case FlipFromLeft
case FlipFromRight
case CurlUp
case CurlDown
}
swift位移枚举的使用
swift里面位移枚举的用法跟OC就完全不一样了,当你去用按位或的运算符时系统会报错,在swift里面应该用数组来表示:
//swift里面位移枚举的定义
let option:UIViewAnimationOptions = [.repeat, .layoutSubviews]
//swift里面普通枚举的定义
let option:UIViewAnimationTransition = .flipFromLeft