iOS開發(fā)中實(shí)用小知識(shí)點(diǎn)有哪些

這篇文章主要介紹iOS開發(fā)中實(shí)用小知識(shí)點(diǎn)有哪些,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

在驛城等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需規(guī)劃網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),營(yíng)銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè),驛城網(wǎng)站建設(shè)費(fèi)用合理。

一、防止UIButton,cell等重復(fù)點(diǎn)擊

主要是快速點(diǎn)擊button或者cell,所對(duì)應(yīng)的action或者邏輯會(huì)走多次,例如:點(diǎn)擊button或者cell調(diào)用撥打電話的方法,會(huì)彈出撥打電話框好多次;這個(gè)對(duì)用戶不太友好;問了下哥們兒,他給了個(gè)宏,目前算是解決這個(gè)問題;代碼如下:

// 防止多次調(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; \
}); \

總的思路是設(shè)置一個(gè)bool變量,記錄一下,延時(shí)更改下變量的值;使用:在所需要的button或者cell的action前調(diào)用即可:

kPreventRepeatClickTime(0.5);

二、獲取當(dāng)前視圖最頂層的ViewController

獲取當(dāng)前視圖最頂層的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;
}

三、代碼截圖相關(guān)

截取指定的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) {
  /// 保存到本地相冊(cè)
  UIImageWriteToSavedPhotosAlbum(viewImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
 }
}

保存圖片的回調(diào)處理

- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{
 if (error) {
  NSLog(@"保存失敗,請(qǐng)重試");
 } else {
  NSLog(@"保存成功");
 }
}

以上是“iOS開發(fā)中實(shí)用小知識(shí)點(diǎn)有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章標(biāo)題:iOS開發(fā)中實(shí)用小知識(shí)點(diǎn)有哪些
分享URL:http://muchs.cn/article46/ihjjeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)云服務(wù)器、小程序開發(fā)、域名注冊(cè)、網(wǎng)站設(shè)計(jì)、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)