日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS-位移枚举简单介绍

發布時間:2024/5/8 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS-位移枚举简单介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

路漫漫其修遠兮,吾將上下而求索。
在蘋果系統以及我們常用的著名的三方框架中,我們經常會遇到位運算,比如像系統中的UIView動畫里面的位運算<<

typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {UIViewAnimationOptionLayoutSubviews = 1 << 0,UIViewAnimationOptionAllowUserInteraction = 1 << 1, // turn on user interaction while animatingUIViewAnimationOptionBeginFromCurrentState = 1 << 2, // start all views from current value, not initial valueUIViewAnimationOptionRepeat = 1 << 3, // repeat animation indefinitelyUIViewAnimationOptionAutoreverse = 1 << 4, // if repeat, run animation back and forthUIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested durationUIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curveUIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only)UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removingUIViewAnimationOptionOverrideInheritedOptions = 1 << 9, // do not inherit any options or animation typeUIViewAnimationOptionCurveEaseInOut = 0 << 16, // defaultUIViewAnimationOptionCurveEaseIn = 1 << 16,UIViewAnimationOptionCurveEaseOut = 2 << 16,UIViewAnimationOptionCurveLinear = 3 << 16,UIViewAnimationOptionTransitionNone = 0 << 20, // defaultUIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,UIViewAnimationOptionTransitionCurlUp = 3 << 20,UIViewAnimationOptionTransitionCurlDown = 4 << 20,UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,UIViewAnimationOptionPreferredFramesPerSecondDefault = 0 << 24,UIViewAnimationOptionPreferredFramesPerSecond60 = 3 << 24,UIViewAnimationOptionPreferredFramesPerSecond30 = 7 << 24,} NS_ENUM_AVAILABLE_IOS(4_0);
亦或像下面的SDWebImage里面的位運算:
typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {SDWebImageDownloaderLowPriority = 1 << 0,SDWebImageDownloaderProgressiveDownload = 1 << 1,/*** By default, request prevent the use of NSURLCache. With this flag, NSURLCache* is used with default policies.*/SDWebImageDownloaderUseNSURLCache = 1 << 2,/*** Call completion block with nil image/imageData if the image was read from NSURLCache* (to be combined with `SDWebImageDownloaderUseNSURLCache`).*/SDWebImageDownloaderIgnoreCachedResponse = 1 << 3,/*** In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for* extra time in background to let the request finish. If the background task expires the operation will be cancelled.*/SDWebImageDownloaderContinueInBackground = 1 << 4,/*** Handles cookies stored in NSHTTPCookieStore by setting * NSMutableURLRequest.HTTPShouldHandleCookies = YES;*/SDWebImageDownloaderHandleCookies = 1 << 5,/*** Enable to allow untrusted SSL certificates.* Useful for testing purposes. Use with caution in production.*/SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,/*** Put the image in the high priority queue.*/SDWebImageDownloaderHighPriority = 1 << 7,/*** Scale down the image*/SDWebImageDownloaderScaleDownLargeImages = 1 << 8, };
那么這種枚舉有什么不一樣的地方呢,其實這種枚舉類型非常強大,也非常好用,下面通過一個小例子來說明:
// 第一種寫法 -這是C的寫法 typedef enum {EnumDemoTypeTop,EnumDemoType1Bottom,}EnumDemoType1;//第二種寫法 -這是OC的寫法 typedef NS_ENUM(NSInteger, EnumDemoType2) {EnumDemoTypeLeft,EnumDemoTypeRight, };//第三種寫法 typedef NS_OPTIONS(NSInteger, EnumDemoActionType) {EnumDemoActionTypeTop = 1<<0, //1*2(0) = 1 /1*二的零次方 = 1EnumDemoActionType1Bottom = 1<<1, //1*2(1)=2EnumDemoActionTypeLeft = 1<<2,//1*2(2)=4EnumDemoActionTypeRight = 1<<3,//1*2(3)=8 };
使用位運算,就可以同時支持多個值:
- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. }- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[self enumDemoType:EnumDemoActionTypeTop | EnumDemoActionType1Bottom | EnumDemoActionTypeLeft | EnumDemoActionTypeRight]; }//按位與 & 1&1==1 1&0==0 0&0==1 只要有0則為0 //按位或 | 1|1==1 1|0==1 0|0=0 只要有1則為1 - (void)enumDemoType:(EnumDemoActionType)type {NSLog(@"type:%ld",type);if (type & EnumDemoActionTypeTop) {NSLog(@"向上----%zd",type & EnumDemoActionTypeTop);}if (type & EnumDemoActionType1Bottom) {NSLog(@"向下----%zd",type & EnumDemoActionType1Bottom);}if (type & EnumDemoActionTypeLeft) {NSLog(@"向左----%zd",type & EnumDemoActionTypeLeft);}if (type & EnumDemoActionTypeRight) {NSLog(@"向右----%zd",type & EnumDemoActionTypeRight);} }
充分的用好枚舉,可以增強代碼的可讀性與健壯性,讓代碼更加的規范。

總結

以上是生活随笔為你收集整理的iOS-位移枚举简单介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。