一般情況下我們?cè)陂_(kāi)發(fā)中可以采用C風(fēng)格的enum 關(guān)鍵字定義枚舉類(lèi)型
enum{
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
}
位移動(dòng)操作枚舉定義
enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;
//使用NSUInteger的地方可以使用UIViewAutoresizing,//UIViewAutoresizing相當(dāng)于NSUInteger的一個(gè)別名使用
//因此一個(gè)UIViewAutoresizing的變量可以直接賦值給NSUInteger
枚舉值一般是4個(gè)字節(jié)的int值辕翰,在64位系統(tǒng)上是8個(gè)字節(jié)
typedef NS_ENUM(NSInteger, UIBarButtonItemStyle) {
UIBarButtonItemStylePlain,// 默認(rèn)從0開(kāi)始
UIBarButtonItemStyleBordered,
UIBarButtonItemStyleDone,
};
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
};
這兩個(gè)宏的定義在framework的NSObjCRuntime中
從枚舉定義來(lái)看嚣潜,NS_ENUM和NS_OPTIONS本質(zhì)是一樣的捉腥。NS_ENUM是通用情況,NS_OPTIONS一般用來(lái)定義具有位移操作或特點(diǎn)的情況