前端之家收集整理的这篇文章主要介绍了
Swift学习笔记 - 位移枚举的按位或运算,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_2@在OC里面我们经常遇到一些枚举值可以多选的,需要用或运算来把这些枚举值链接起来,这样的我们称为位移枚举,但是在swift里面却不能这么做,下面来讲解一下如何在swift里面使用
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位移枚举的使用
@H_
404_2@OC里面位移枚举的使用一般用按位或运算符,也就是
|
运算符。
enum UIViewAnimationOptions option = UIViewAnimationOptionRepeat | UIViewAnimationOptionLayoutSubviews;
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位移枚举的使用
@H_
404_2@swift里面位移枚举的
用法跟OC就完全不一样了,当你去用按位或的运算符时系统会报错,在swift里面应该用数组来表示:
let option:UIViewAnimationOptions = [.repeat,.layoutSubviews]
let option:UIViewAnimationTransition = .flipFromLeft
@H_404_2@以上就是关于swift里面位移枚举的使用小结,如果写的有什么不对的欢迎大家补充,希望大家能学到,谢谢大家的阅读~