OC的位移枚举的区分在OC里面我们经常遇到一些枚举值可以多选的,需要用或运算来把这些枚举值链接起来,这样的我们称为位移枚举,但是在swift里面却不能这么做,下面来讲解一下如何在swift里面使用
//位移枚举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
总结以上就是关于swift里面位移枚举的使用小结,如果写的有什么不对的欢迎大家补充,希望大家能学到,谢谢大家的阅读~
以上是内存溢出为你收集整理的Swift学习笔记 - 位移枚举的按位或运算全部内容,希望文章能够帮你解决Swift学习笔记 - 位移枚举的按位或运算所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)