這篇文章主要介紹iOS開發(fā)中實用小知識點有哪些,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
在驛城等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供成都網(wǎng)站設計、成都網(wǎng)站制作 網(wǎng)站設計制作按需規(guī)劃網(wǎng)站,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,高端網(wǎng)站設計,營銷型網(wǎng)站建設,成都外貿(mào)網(wǎng)站建設,驛城網(wǎng)站建設費用合理。
一、防止UIButton,cell等重復點擊
主要是快速點擊button或者cell,所對應的action或者邏輯會走多次,例如:點擊button或者cell調(diào)用撥打電話的方法,會彈出撥打電話框好多次;這個對用戶不太友好;問了下哥們兒,他給了個宏,目前算是解決這個問題;代碼如下:
// 防止多次調(diào)用 #define kPreventRepeatClickTime(_seconds_) \ static BOOL shouldPrevent; \ if (shouldPrevent) return; \ shouldPrevent = YES; \ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ \ shouldPrevent = NO; \ }); \
總的思路是設置一個bool變量,記錄一下,延時更改下變量的值;使用:在所需要的button或者cell的action前調(diào)用即可:
kPreventRepeatClickTime(0.5);
二、獲取當前視圖最頂層的ViewController
獲取當前視圖最頂層的ViewController
+ (UIViewController *)currentViewController { UIWindow * window = [[UIApplication sharedApplication] keyWindow]; if (window.windowLevel != UIWindowLevelNormal){ NSArray *windows = [[UIApplication sharedApplication] windows]; for(UIWindow * tmpWin in windows){ if (tmpWin.windowLevel == UIWindowLevelNormal){ window = tmpWin; break; } } } UIViewController *currentVC = window.rootViewController; while (currentVC.presentedViewController) { currentVC = currentVC.presentedViewController; } if ([currentVC isKindOfClass:[UITabBarController class]]) { currentVC = [(UITabBarController *)currentVC selectedViewController]; } if ([currentVC isKindOfClass:[UINavigationController class]]) { currentVC = [(UINavigationController *)currentVC topViewController]; } return currentVC; }
三、代碼截圖相關
截取指定的View:
/// 截屏 - (void)actionForScreenShotWith:(UIView *)aimView savePhoto:(BOOL)savePhoto { if (!aimView) return; UIGraphicsBeginImageContextWithOptions(aimView.bounds.size, NO, 0.0f); [aimView.layer renderInContext: UIGraphicsGetCurrentContext()]; UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (savePhoto) { /// 保存到本地相冊 UIImageWriteToSavedPhotosAlbum(viewImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); } }
保存圖片的回調(diào)處理
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{ if (error) { NSLog(@"保存失敗,請重試"); } else { NSLog(@"保存成功"); } }
以上是“iOS開發(fā)中實用小知識點有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
文章標題:iOS開發(fā)中實用小知識點有哪些
分享URL:http://chinadenli.net/article46/ihjjeg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設、云服務器、小程序開發(fā)、域名注冊、網(wǎng)站設計、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)