iOS知識 - 常用小技巧大雜燴

``***
Git hub 地址 : https://github.com/bigsen/iOS_Tips


1,打印View所有子視圖

po [[self view]recursiveDescription]

2枯冈,layoutSubviews調(diào)用的調(diào)用時機(jī)

* 當(dāng)視圖第一次顯示的時候會被調(diào)用毅贮。
* 添加子視圖也會調(diào)用這個方法。
* 當(dāng)本視圖的大小發(fā)生改變的時候是會調(diào)用的。
* 當(dāng)子視圖的frame發(fā)生改變的時候是會調(diào)用的烘挫。
* 當(dāng)刪除子視圖的時候是會調(diào)用的.

3绿满,NSString過濾特殊字符

// 定義一個特殊字符的集合
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:
@"@/:殖属;()¥「」"、[]{}#%-*+=_\\|~<>$€^?'@#$%^&*()_+'\""];
// 過濾字符串的特殊字符
NSString *newString = [trimString stringByTrimmingCharactersInSet:set];

4巧勤,TransForm屬性

//平移按鈕
CGAffineTransform transForm = self.buttonView.transform;
self.buttonView.transform = CGAffineTransformTranslate(transForm, 10, 0);

//旋轉(zhuǎn)按鈕
CGAffineTransform transForm = self.buttonView.transform;
self.buttonView.transform = CGAffineTransformRotate(transForm, M_PI_4);

//縮放按鈕
self.buttonView.transform = CGAffineTransformScale(transForm, 1.2, 1.2);

//初始化復(fù)位
self.buttonView.transform = CGAffineTransformIdentity;

5延曙,去掉分割線多余15像素

首先在viewDidLoad方法加入以下代碼:
 if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];    
}   
 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {        
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在重寫willDisplayCell方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath{   
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {       
             [cell setSeparatorInset:UIEdgeInsetsZero];    
    }    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {        
             [cell setLayoutMargins:UIEdgeInsetsZero];    
    }
}

6截型,計算方法耗時時間間隔

// 獲取時間間隔
#define TICK   CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define TOCK   NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

7精堕,Color顏色宏定義

// 隨機(jī)顏色
#define RANDOM_COLOR [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
// 顏色(RGB)
#define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
// 利用這種方法設(shè)置顏色和透明值,可不影響子視圖背景色
#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

8扭仁,Alert提示宏定義

#define Alert(_S_, ...) [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(_S_), ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil] show]

8徐许,讓 iOS 應(yīng)用直接退出

- (void)exitApplication {
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    UIWindow *window = app.window;

    [UIView animateWithDuration:1.0f animations:^{
        window.alpha = 0;
    } completion:^(BOOL finished) {
        exit(0);
    }];
}

**8,NSArray 快速求總和 最大值 最小值 和 平均值 **

NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil];
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
NSLog(@"%f\n%f\n%f\n%f",sum,avg,max,min);

9仇箱,修改Label中不同文字顏色

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self editStringColor:self.label.text editStr:@"好" color:[UIColor blueColor]];
}

- (void)editStringColor:(NSString *)string editStr:(NSString *)editStr color:(UIColor *)color {
    // string為整體字符串, editStr為需要修改的字符串
    NSRange range = [string rangeOfString:editStr];

    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:string];

    // 設(shè)置屬性修改字體顏色UIColor與大小UIFont
    [attribute addAttributes:@{NSForegroundColorAttributeName:color} range:range];

    self.label.attributedText = attribute;
}

10冤议,播放聲音

  #import<AVFoundation/AVFoundation.h>
   //  1.獲取音效資源的路徑
   NSString *path = [[NSBundle mainBundle]pathForResource:@"pour_milk" ofType:@"wav"];
   //  2.將路勁轉(zhuǎn)化為url
   NSURL *tempUrl = [NSURL fileURLWithPath:path];
   //  3.用轉(zhuǎn)化成的url創(chuàng)建一個播放器
   NSError *error = nil;
   AVAudioPlayer *play = [[AVAudioPlayer alloc]initWithContentsOfURL:tempUrl error:&error];
   self.player = play;
   //  4.播放
   [play play];

11,檢測是否IPad Pro和其它設(shè)備型號

- (BOOL)isIpadPro
{   
  UIScreen *Screen = [UIScreen mainScreen];   
  CGFloat width = Screen.nativeBounds.size.width/Screen.nativeScale;  
  CGFloat height = Screen.nativeBounds.size.height/Screen.nativeScale;         
  BOOL isIpad =[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;   
  BOOL hasIPadProWidth = fabs(width - 1024.f) < DBL_EPSILON;    
  BOOL hasIPadProHeight = fabs(height - 1366.f) < DBL_EPSILON;  
  return isIpad && hasIPadProHeight && hasIPadProWidth;
}

#define UI_IS_LANDSCAPE ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight)#define UI_IS_IPAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)#define UI_IS_IPHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)#define UI_IS_IPHONE4 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height < 568.0)#define UI_IS_IPHONE5 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)#define UI_IS_IPHONE6 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)#define UI_IS_IPHONE6PLUS (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0 || [[UIScreen mainScreen] bounds].size.width == 736.0) // Both orientations#define UI_IS_IOS8_AND_HIGHER ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)

文/Originalee(簡書作者)原文鏈接:http://www.reibang.com/p/9d36aa12429f著作權(quán)歸作者所有发笔,轉(zhuǎn)載請聯(lián)系作者獲得授權(quán)量蕊,并標(biāo)注“簡書作者”残炮。

11,修改Tabbar Item的屬性

    // 修改標(biāo)題位置
    self.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -10);
    // 修改圖片位置
    self.tabBarItem.imageInsets = UIEdgeInsetsMake(-3, 0, 3, 0);

    // 批量修改屬性
    for (UIBarItem *item in self.tabBarController.tabBar.items) {
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                 [UIFont fontWithName:@"Helvetica" size:19.0], NSFontAttributeName, nil]
                            forState:UIControlStateNormal];
    }

    // 設(shè)置選中和未選中字體顏色
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

    //未選中字體顏色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} forState:UIControlStateNormal];

    //選中字體顏色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor cyanColor]} forState:UIControlStateSelected];

12莉炉,NULL - nil - Nil - NSNULL的區(qū)別

* nil是OC的,空對象服协,地址指向空(0)的對象绍昂。對象的字面零值

* Nil是Objective-C類的字面零值

* NULL是C的,空地址偿荷,地址的數(shù)值是0窘游,是個長整數(shù)

* NSNull用于解決向NSArray和NSDictionary等集合中添加空值的問題

11,去掉BackBarButtonItem的文字

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];

12跳纳,控件不能交互的一些原因

1忍饰,控件的userInteractionEnabled = NO
2,透明度小于等于0.01寺庄,aplpha
3艾蓝,控件被隱藏的時候力崇,hidden = YES
4,子視圖的位置超出了父視圖的有效范圍赢织,子視圖無法交互亮靴,設(shè)置了。
5于置,需要交互的視圖茧吊,被其他視圖蓋住(其他視圖開啟了用戶交互)俱两。

12饱狂,修改UITextField中Placeholder的文字顏色

[text setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
}

13,視圖的生命周期

1宪彩、 alloc 創(chuàng)建對象休讳,分配空間
2、 init (initWithNibName) 初始化對象尿孔,初始化數(shù)據(jù)
3俊柔、 loadView 從nib載入視圖 ,除非你沒有使用xib文件創(chuàng)建視圖
4活合、 viewDidLoad 載入完成雏婶,可以進(jìn)行自定義數(shù)據(jù)以及動態(tài)創(chuàng)建其他控件
5、 viewWillAppear視圖將出現(xiàn)在屏幕之前白指,馬上這個視圖就會被展現(xiàn)在屏幕上了
6留晚、 viewDidAppear 視圖已在屏幕上渲染完成

1、viewWillDisappear 視圖將被從屏幕上移除之前執(zhí)行
2告嘲、viewDidDisappear 視圖已經(jīng)被從屏幕上移除错维,用戶看不到這個視圖了
3、dealloc 視圖被銷毀橄唬,此處需要對你在init和viewDidLoad中創(chuàng)建的對象進(jìn)行釋放.

viewVillUnload- 當(dāng)內(nèi)存過低赋焕,即將釋放時調(diào)用;
viewDidUnload-當(dāng)內(nèi)存過低仰楚,釋放一些不需要的視圖時調(diào)用隆判。

14,應(yīng)用程序的生命周期

1僧界,啟動但還沒進(jìn)入狀態(tài)保存 :
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

2侨嘀,基本完成程序準(zhǔn)備開始運(yùn)行:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 
3,當(dāng)應(yīng)用程序?qū)⒁敕腔顒訝顟B(tài)執(zhí)行捂襟,應(yīng)用程序不接收消息或事件咬腕,比如來電話了:
- (void)applicationWillResignActive:(UIApplication *)application 

4,當(dāng)應(yīng)用程序入活動狀態(tài)執(zhí)行笆豁,這個剛好跟上面那個方法相反:
- (void)applicationDidBecomeActive:(UIApplication *)application   

5郎汪,當(dāng)程序被推送到后臺的時候調(diào)用赤赊。所以要設(shè)置后臺繼續(xù)運(yùn)行,則在這個函數(shù)里面設(shè)置即可:
- (void)applicationDidEnterBackground:(UIApplication *)application  

6煞赢,當(dāng)程序從后臺將要重新回到前臺時候調(diào)用抛计,這個剛好跟上面的那個方法相反:
- (void)applicationWillEnterForeground:(UIApplication *)application  

7,當(dāng)程序?qū)⒁顺鍪潜徽{(diào)用照筑,通常是用來保存數(shù)據(jù)和一些退出前的清理工作:
- (void)applicationWillTerminate:(UIApplication *)application  

15吹截,判斷view是不是指定視圖的子視圖

 BOOL isView =  [textView isDescendantOfView:self.view];

16,判斷對象是否遵循了某協(xié)議

if ([self.selectedController conformsToProtocol:@protocol(RefreshPtotocol)]) {
    [self.selectedController performSelector:@selector(onTriggerRefresh)];
}

17凝危,頁面強(qiáng)制橫屏

#pragma mark - 強(qiáng)制橫屏代碼
- (BOOL)shouldAutorotate{    
    //是否支持轉(zhuǎn)屏       
    return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{    
    //支持哪些轉(zhuǎn)屏方向    
    return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{               
    return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)prefersStatusBarHidden{   
    return NO;
}

18波俄,系統(tǒng)鍵盤通知消息

1、UIKeyboardWillShowNotification-將要彈出鍵盤
2蛾默、UIKeyboardDidShowNotification-顯示鍵盤
3懦铺、UIKeyboardWillHideNotification-將要隱藏鍵盤
4、UIKeyboardDidHideNotification-鍵盤已經(jīng)隱藏
5支鸡、UIKeyboardWillChangeFrameNotification-鍵盤將要改變frame
6冬念、UIKeyboardDidChangeFrameNotification-鍵盤已經(jīng)改變frame

19,關(guān)閉navigationController的滑動返回手勢

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

20牧挣,設(shè)置狀態(tài)欄背景為任意的顏色

- (void)setStatusColor
{
    UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
    statusBarView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:statusBarView];
}

21急前,讓Xcode的控制臺支持LLDB類型的打印

打開終端輸入三條命令:
    touch ~/.lldbinit
    echo display @import UIKit >> ~/.lldbinit
    echo target stop-hook add -o \"target stop-hook disable\" >> ~/.lldbinit

下次重新運(yùn)行項目,然后就不報錯了瀑构。


22裆针,Label行間距

-(void)test{
    NSMutableAttributedString *attributedString =    
   [[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
    NSMutableParagraphStyle *paragraphStyle =  [[NSMutableParagraphStyle alloc] init];  
   [paragraphStyle setLineSpacing:3];

    //調(diào)整行間距       
   [attributedString addAttribute:NSParagraphStyleAttributeName 
                         value:paragraphStyle 
                         range:NSMakeRange(0, [self.contentLabel.text length])];
     self.contentLabel.attributedText = attributedString;
}

23,UIImageView填充模式

@"UIViewContentModeScaleToFill",      // 拉伸自適應(yīng)填滿整個視圖  
@"UIViewContentModeScaleAspectFit",   // 自適應(yīng)比例大小顯示  
@"UIViewContentModeScaleAspectFill",  // 原始大小顯示  
@"UIViewContentModeRedraw",           // 尺寸改變時重繪  
@"UIViewContentModeCenter",           // 中間  
@"UIViewContentModeTop",              // 頂部  
@"UIViewContentModeBottom",           // 底部  
@"UIViewContentModeLeft",             // 中間貼左  
@"UIViewContentModeRight",            // 中間貼右  
@"UIViewContentModeTopLeft",          // 貼左上  
@"UIViewContentModeTopRight",         // 貼右上  
@"UIViewContentModeBottomLeft",       // 貼左下  
@"UIViewContentModeBottomRight",      // 貼右下  

24寺晌,宏定義檢測block是否可用

#define BLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); };   
// 宏定義之前的用法
 if (completionBlock)   {   
    completionBlock(arg1, arg2); 
  }    
// 宏定義之后的用法
 BLOCK_EXEC(completionBlock, arg1, arg2);

25世吨,Debug欄打印時自動把Unicode編碼轉(zhuǎn)化成漢字

// 有時候我們在xcode中打印中文,會打印出Unicode編碼,還需要自己去一些在線網(wǎng)站轉(zhuǎn)換,有了插件就方便多了。
 DXXcodeConsoleUnicodePlugin 插件

26折剃,設(shè)置狀態(tài)欄文字樣式顏色

[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

26另假,自動生成模型代碼的插件

// 可自動生成模型的代碼像屋,省去寫模型代碼的時間
ESJsonFormat-for-Xcode

27怕犁,iOS中的一些手勢

輕擊手勢(TapGestureRecognizer)
輕掃手勢(SwipeGestureRecognizer)
長按手勢(LongPressGestureRecognizer)
拖動手勢(PanGestureRecognizer)
捏合手勢(PinchGestureRecognizer)
旋轉(zhuǎn)手勢(RotationGestureRecognizer)

27,iOS 開發(fā)中一些相關(guān)的路徑

模擬器的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs 

文檔安裝位置:
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets
 
插件保存路徑:
~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins

自定義代碼段的保存路徑:
~/Library/Developer/Xcode/UserData/CodeSnippets/ 
如果找不到CodeSnippets文件夾己莺,可以自己新建一個CodeSnippets文件夾奏甫。

證書路徑
~/Library/MobileDevice/Provisioning Profiles

28,獲取 iOS 路徑的方法

獲取家目錄路徑的函數(shù)
NSString *homeDir = NSHomeDirectory();

獲取Documents目錄路徑的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];

獲取Documents目錄路徑的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];

獲取tmp目錄路徑的方法:
NSString *tmpDir = NSTemporaryDirectory();

**29凌受,字符串相關(guān)操作 **

去除所有的空格
[str stringByReplacingOccurrencesOfString:@" " withString:@""]

去除首尾的空格
[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

- (NSString *)uppercaseString; 全部字符轉(zhuǎn)為大寫字母
- (NSString *)lowercaseString 全部字符轉(zhuǎn)為小寫字母

30阵子, CocoaPods pod install/pod update更新慢的問題

pod install --verbose --no-repo-update 
pod update --verbose --no-repo-update
如果不加后面的參數(shù),默認(rèn)會升級CocoaPods的spec倉庫胜蛉,加一個參數(shù)可以省略這一步挠进,然后速度就會提升不少色乾。

31,MRC和ARC混編設(shè)置方式


在XCode中targets的build phases選項下Compile Sources下選擇 不需要arc編譯的文件
雙擊輸入 -fno-objc-arc 即可

MRC工程中也可以使用ARC的類领突,方法如下:
在XCode中targets的build phases選項下Compile Sources下選擇要使用arc編譯的文件
雙擊輸入 -fobjc-arc 即可

32暖璧,把tableview里cell的小對勾的顏色改成別的顏色

_mTableView.tintColor = [UIColor redColor];

33,調(diào)整tableview的separaLine線的位置

tableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);

34君旦,設(shè)置滑動的時候隱藏navigationbar

navigationController.hidesBarsOnSwipe = Yes

35澎办,自動處理鍵盤事件,實(shí)現(xiàn)輸入框防遮擋的插件

IQKeyboardManager
https://github.com/hackiftekhar/IQKeyboardManager

36金砍,Quartz2D相關(guān)

圖形上下是一個CGContextRef類型的數(shù)據(jù)局蚀。
圖形上下文包含:
1,繪圖路徑(各種各樣圖形)
2恕稠,繪圖狀態(tài)(顏色琅绅,線寬攀圈,樣式蝗羊,旋轉(zhuǎn)饿自,縮放刑枝,平移)
3西乖,輸出目標(biāo)(繪制到什么地方去惧辈?UIView抖拴、圖片)

1痪寻,獲取當(dāng)前圖形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
2凑懂,添加線條
CGContextMoveToPoint(ctx, 20, 20);
3煤痕,渲染
CGContextStrokePath(ctx);
CGContextFillPath(ctx);
4,關(guān)閉路徑
CGContextClosePath(ctx);
5接谨,畫矩形
CGContextAddRect(ctx, CGRectMake(20, 20, 100, 120));
6摆碉,設(shè)置線條顏色
[[UIColor redColor] setStroke];
7, 設(shè)置線條寬度
CGContextSetLineWidth(ctx, 20);
8脓豪,設(shè)置頭尾樣式
CGContextSetLineCap(ctx, kCGLineCapSquare);
9巷帝,設(shè)置轉(zhuǎn)折點(diǎn)樣式
CGContextSetLineJoin(ctx, kCGLineJoinBevel);
10,畫圓
CGContextAddEllipseInRect(ctx, CGRectMake(30, 50, 100, 100));
11扫夜,指定圓心
CGContextAddArc(ctx, 100, 100, 50, 0, M_PI * 2, 1);
12楞泼,獲取圖片上下文
UIGraphicsGetImageFromCurrentImageContext();
13,保存圖形上下文
CGContextSaveGState(ctx)
14笤闯,恢復(fù)圖形上下文
CGContextRestoreGState(ctx)

37堕阔,屏幕截圖

    // 1. 開啟一個與圖片相關(guān)的圖形上下文
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0.0);

    // 2. 獲取當(dāng)前圖形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 3. 獲取需要截取的view的layer
    [self.view.layer renderInContext:ctx];

    // 4. 從當(dāng)前上下文中獲取圖片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    // 5. 關(guān)閉圖形上下文
    UIGraphicsEndImageContext();

    // 6. 把圖片保存到相冊
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

37,左右抖動動畫

//1, 創(chuàng)建核心動畫
CAKeyframeAnimation *keyAnima = [CAKeyframeAnimation animation]; 

//2, 告訴系統(tǒng)執(zhí)行什么動畫颗味。
keyAnima.keyPath = @"transform.rotation"; 
keyAnima.values = @[@(-M_PI_4 /90.0 * 5),@(M_PI_4 /90.0 * 5),@(-M_PI_4 /90.0 * 5)]; 

//  3, 執(zhí)行完之后不刪除動畫 
keyAnima.removedOnCompletion = NO; 

// 4, 執(zhí)行完之后保存最新的狀態(tài) 
keyAnima.fillMode = kCAFillModeForwards; 

// 5, 動畫執(zhí)行時間 
keyAnima.duration = 0.2; 

// 6, 設(shè)置重復(fù)次數(shù)超陆。 
keyAnima.repeatCount = MAXFLOAT; 

// 7, 添加核心動畫 
[self.iconView.layer addAnimation:keyAnima forKey:nil];

38,CALayer 的知識

CALayer  負(fù)責(zé)視圖中顯示內(nèi)容和動畫
UIView     負(fù)責(zé)監(jiān)聽和響應(yīng)事件

創(chuàng)建UIView對象時浦马,UIView內(nèi)部會自動創(chuàng)建一個圖層(既CALayer)
UIView本身不具備顯示的功能时呀,是它內(nèi)部的層才有顯示功能.

CALayer屬性:
position  中點(diǎn)(由anchorPoint決定)
anchorPoint 錨點(diǎn)
borderColor 邊框顏色
borderWidth 邊框?qū)挾?cornerRadius 圓角半徑
shadowColor 陰影顏色
contents 內(nèi)容
opacity 透明度
shadowOpacity 偏移
shadowRadius 陰影半徑
shadowColor 陰影顏色
masksToBounds 裁剪

39张漂,性能相關(guān)

1. 視圖復(fù)用,比如UITableViewCell,UICollectionViewCell.
2. 數(shù)據(jù)緩存,比如用SDWebImage實(shí)現(xiàn)圖片緩存。
3. 任何情況下都不能堵塞主線程谨娜,把耗時操作盡量放到子線程鹃锈。
4. 如果有多個下載同時并發(fā),可以控制并發(fā)數(shù)瞧预。
5. 在合適的地方盡量使用懶加載屎债。
6. 重用重大開銷對象,比如:NSDateFormatter垢油、NSCalendar盆驹。
7. 選擇合適的數(shù)據(jù)存儲。
8. 避免循環(huán)引用滩愁。避免delegate用retain躯喇、strong修飾,block可能導(dǎo)致循環(huán)引用硝枉,NSTimer也可能導(dǎo)致內(nèi)存泄露等廉丽。
9. 當(dāng)涉及到定位的時候,不用的時候最好把定位服務(wù)關(guān)閉妻味。因?yàn)槎ㄎ缓碾娬埂⒘髁俊?10. 加鎖對性能有重大開銷。
11. 界面最好不要添加過多的subViews.
12. TableView 如果不同行高责球,那么返回行高焦履,最好做緩存。
13. Viewdidload 里盡量不要做耗時操作雏逾。

40嘉裤,驗(yàn)證身份證號碼

//驗(yàn)證身份證號碼
- (BOOL)checkIdentityCardNo:(NSString*)cardNo
{
    if (cardNo.length != 18) {
        return  NO;
    }
    NSArray* codeArray = [NSArray arrayWithObjects:@"7",@"9",@"10",@"5",@"8",@"4",@"2",@"1",@"6",@"3",@"7",@"9",@"10",@"5",@"8",@"4",@"2", nil];
    NSDictionary* checkCodeDic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1",@"0",@"X",@"9",@"8",@"7",@"6",@"5",@"4",@"3",@"2", nil]  forKeys:[NSArray arrayWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil]];

    NSScanner* scan = [NSScanner scannerWithString:[cardNo substringToIndex:17]];

    int val;
    BOOL isNum = [scan scanInt:&val] && [scan isAtEnd];
    if (!isNum) {
        return NO;
    }
    int sumValue = 0;

    for (int i =0; i<17; i++) {
        sumValue+=[[cardNo substringWithRange:NSMakeRange(i , 1) ] intValue]* [[codeArray objectAtIndex:i] intValue];
    }

    NSString* strlast = [checkCodeDic objectForKey:[NSString stringWithFormat:@"%d",sumValue%11]];

    if ([strlast isEqualToString: [[cardNo substringWithRange:NSMakeRange(17, 1)]uppercaseString]]) {
        return YES;
    }
    return  NO;
}

41,響應(yīng)者鏈條順序

1> 當(dāng)應(yīng)用程序啟動以后創(chuàng)建 UIApplication 對象

2> 然后啟動“消息循環(huán)”監(jiān)聽所有的事件

3> 當(dāng)用戶觸摸屏幕的時候, "消息循環(huán)"監(jiān)聽到這個觸摸事件

4> "消息循環(huán)" 首先把監(jiān)聽到的觸摸事件傳遞了 UIApplication 對象

5> UIApplication 對象再傳遞給 UIWindow 對象

6> UIWindow 對象再傳遞給 UIWindow 的根控制器(rootViewController)

7> 控制器再傳遞給控制器所管理的 view

8> 控制器所管理的 View 在其內(nèi)部搜索看本次觸摸的點(diǎn)在哪個控件的范圍內(nèi)(調(diào)用Hit test檢測是否在這個范圍內(nèi))

9> 找到某個控件以后(調(diào)用這個控件的 touchesXxx 方法), 再一次向上返回, 最終返回給"消息循環(huán)"

10> "消息循環(huán)"知道哪個按鈕被點(diǎn)擊后, 在搜索這個按鈕是否注冊了對應(yīng)的事件, 如果注冊了, 那么就調(diào)用這個"事件處理"程序栖博。(一般就是執(zhí)行控制器中的"事件處理"方法)

42屑宠,使用函數(shù)式指針執(zhí)行方法和忽略performSelector方法的時候警告

不帶參數(shù)的:
SEL selector = NSSelectorFromString(@"someMethod");
IMP imp = [_controller methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(_controller, selector);

帶參數(shù)的:
SEL selector = NSSelectorFromString(@"processRegion:ofView:");
IMP imp = [_controller methodForSelector:selector];
CGRect (*func)(id, SEL, CGRect, UIView *) = (void *)imp;
CGRect result = func(_controller, selector, someRect, someView);

忽略警告:
#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  [someController performSelector: NSSelectorFromString(@"someMethod")]
#pragma clang diagnostic pop

如果需要忽視的警告有多處,可以定義一個宏:
#define SuppressPerformSelectorLeakWarning(Stuff) \ 
   do {\ 
          _Pragma("clang diagnostic push") \ 
          _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
      Stuff; \
          _Pragma("clang diagnostic pop") \ 
   } while (0)
使用方法:
SuppressPerformSelectorLeakWarning( 
  [_target performSelector:_action withObject:self]
);

43仇让,UIApplication的簡單使用

--------設(shè)置角標(biāo)數(shù)字--------
    //獲取UIApplication對象
    UIApplication *ap = [UIApplication sharedApplication];
    //在設(shè)置之前, 要注冊一個通知,從ios8之后,都要先注冊一個通知對象.才能夠接收到提醒.
    UIUserNotificationSettings *notice =
    [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
    //注冊通知對象
    [ap registerUserNotificationSettings:notice];
    //設(shè)置提醒數(shù)字
    ap.applicationIconBadgeNumber = 20;

--------設(shè)置聯(lián)網(wǎng)狀態(tài)--------
    UIApplication *ap = [UIApplication sharedApplication];
    ap.networkActivityIndicatorVisible = YES;
--------------------------

44, UITableView隱藏空白部分線條

self.tableView.tableFooterView =  [[UIView alloc]init];

45典奉,顯示git增量的Xcode插件:GitDiff

下載地址:https://github.com/johnno1962/GitDiff
這款插件的名字是GitDiff,作用就是可以顯示表示出git增量提交的代碼行妹孙,比如下圖
會在Xcode左邊標(biāo)識出來:

46秋柄,各種收藏的網(wǎng)址

unicode編碼轉(zhuǎn)換
http://tool.chinaz.com/tools/unicode.aspx    

JSON 字符串格式化
http://www.runoob.com/jsontool

RGB 顏色值轉(zhuǎn)換
http://www.sioe.cn/yingyong/yanse-rgb-16/

短網(wǎng)址生成
http://dwz.wailian.work/

MAC 軟件下載
http://www.waitsun.com/

objc 中國
http://objccn.io/

47获枝,NSObject 繼承圖


48蠢正,淺拷貝、深拷貝省店、copy和strong

淺拷貝:(任何一方的變動都會影響到另一方)
只是對對象的簡單拷貝嚣崭,讓幾個對象共用一片內(nèi)存笨触,當(dāng)內(nèi)存銷毀的時候,指向這片內(nèi)存的幾個指針
需要重新定義才可以使用雹舀。

深拷貝:(任何一方的變動都不會影響到另一方)
拷貝對象的具體內(nèi)容芦劣,內(nèi)存地址是自主分配的,拷貝結(jié)束后说榆,兩個對象雖然存的值是相同的虚吟,但是
內(nèi)存地址不一樣,兩個對象也互不影響签财,互不干涉串慰。

copy和Strong的區(qū)別:copy是創(chuàng)建一個新對象,Strong是創(chuàng)建一個指針唱蒸。

49邦鲫,SEL 和 IMP

SEL: 其實(shí)是對方法的一種包裝,將方法包裝成一個SEL類型的數(shù)據(jù),去尋找對應(yīng)的方法地址,找到方法地址后
就可以調(diào)用方法。這些都是運(yùn)行時特性,發(fā)消息就是發(fā)送SEL,然后根據(jù)SEL找到地址,調(diào)用方法神汹。


IMP:  是”implementation”的縮寫,它是objetive-C 方法 (method)實(shí)現(xiàn)代碼塊的地址,類似函數(shù)
指針,通過它可以 直接訪問任意一個方法庆捺。免去發(fā)送消息的代價。

50, self 和 super

在動態(tài)方法中屁魏,self代表著"對象"
在靜態(tài)方法中滔以,self代表著"類"

萬變不離其宗,記住一句話就行了:
self代表著當(dāng)前方法的調(diào)用者self 和 super 是oc提供的 兩個保留字, 但有根本區(qū)別氓拼,self是類的隱藏的
參數(shù)變量,指向當(dāng)前調(diào)用方法的對象(類也是對象醉者,類對象)
另一個隱藏參數(shù)是_cmd,代表當(dāng)前類方法的selector披诗。

super并不是隱藏的參數(shù),它只是一個"編譯器指示符"
super 就是個障眼法 發(fā)撬即,編譯器符號, 它可以替換成 [self class],只不過 方法是從 self 的
超類開始尋找呈队。

51, 長連接 和 短連接

長連接:(長連接在沒有數(shù)據(jù)通信時剥槐,定時發(fā)送數(shù)據(jù)包(心跳),以維持連接狀態(tài))
連接→數(shù)據(jù)傳輸→保持連接(心跳)→數(shù)據(jù)傳輸→保持連接(心跳)→……→關(guān)閉連接宪摧;  
長連接:連接服務(wù)器就不斷開

短連接:(短連接在沒有數(shù)據(jù)傳輸時直接關(guān)閉就行了)
連接→數(shù)據(jù)傳輸→關(guān)閉連接粒竖;
短連接:連接上服務(wù)器,獲取完數(shù)據(jù)几于,就立即斷開蕊苗。

52, HTTP 基本狀態(tài)碼

200 OK
    請求已成功,請求所希望的響應(yīng)頭或數(shù)據(jù)體將隨此響應(yīng)返回沿彭。

300 Multiple Choices
    被請求的資源有一系列可供選擇的回饋信息朽砰,每個都有自己特定的地址和瀏覽器驅(qū)動的商議信息。用戶或?yàn)g覽器能夠自行選擇一個首選的地址進(jìn)行重定向。

400 Bad Request
    由于包含語法錯誤瞧柔,當(dāng)前請求無法被服務(wù)器理解漆弄。除非進(jìn)行修改,否則客戶端不應(yīng)該重復(fù)提交這個請求造锅。

404 Not Found
    請求失敗撼唾,請求所希望得到的資源未被在服務(wù)器上發(fā)現(xiàn)。沒有信息能夠告訴用戶這個狀況到底是暫時的還是永久的哥蔚。假如服務(wù)器知道情況的話倒谷,應(yīng)當(dāng)使用410狀態(tài)碼來告知舊資源因?yàn)槟承﹥?nèi)部的配置機(jī)制問題,已經(jīng)永久的不可用糙箍,而且沒有任何可以跳轉(zhuǎn)的地址恨锚。404這個狀態(tài)碼被廣泛應(yīng)用于當(dāng)服務(wù)器不想揭示到底為何請求被拒絕或者沒有其他適合的響應(yīng)可用的情況下。

408 Request Timeout
    請求超時倍靡『锪妫客戶端沒有在服務(wù)器預(yù)備等待的時間內(nèi)完成一個請求的發(fā)送∷鳎客戶端可以隨時再次提交這一請求而無需進(jìn)行任何更改他挎。

500 Internal Server Error
    服務(wù)器遇到了一個未曾預(yù)料的狀況,導(dǎo)致了它無法完成對請求的處理捡需。一般來說办桨,這個問題都會在服務(wù)器的程序碼出錯時出現(xiàn)。

53, TCP 和 UDP

TCP:

- 建立連接站辉,形成傳輸數(shù)據(jù)的通道
- 在連接中進(jìn)行大數(shù)據(jù)傳輸(數(shù)據(jù)大小受限制)
- 通過三次握手完成連接呢撞,是可靠協(xié)議
- 必須建立連接,效率比UDP低

UDP:

- 只管發(fā)送饰剥,不管接受
- 將數(shù)據(jù)以及源和目的封裝成數(shù)據(jù)包中殊霞,不需要建立連接、
- 每個數(shù)據(jù)報的大小限制在64K之內(nèi)
- 不可靠協(xié)議
- 速度快

54, 三次握手和四次斷開

三次握手:
     你在嗎-我在的-我問你個事情
四次斷開握手
     我這個問題問完了--你問完了嗎---可以下線了嗎---我真的問完了拜拜

55, 設(shè)置按鈕按下時候會發(fā)光

button.showsTouchWhenHighlighted=YES;

56汰蓉,怎么把tableview里Cell的小對勾顏色改成別的顏色绷蹲?

_mTableView.tintColor = [UIColor redColor];  

57, 怎么調(diào)整Cell 的 separaLine的位置?**

_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);  

58, ScrollView莫名其妙不能在viewController劃到頂怎么辦顾孽?

self.automaticallyAdjustsScrollViewInsets = NO;  

59, 設(shè)置TableView不顯示沒內(nèi)容的Cell祝钢。

self.tableView.tableFooterView = [[UIView alloc]init]

60,復(fù)制字符串到iOS剪貼板

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.label.text;

61若厚,宏定義多行使用方法

例子:( 只需要每行加個 \ 就行了)

#define YKCodingScanData \
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{} \
- (instancetype)initWithScanJson:(NSDictionary *)dict{ \
if (self = [super init]) { \
[self setValuesForKeysWithDictionary:dict]; \
} \
    return self; \
} \

62拦英,去掉cell點(diǎn)擊后背景變色

[tableView deselectRowAtIndexPath:indexPath animated:NO];
如果發(fā)現(xiàn)在tableView的didSelect中present控制器彈出有些慢也可以試試這個方法

63,線程租調(diào)度事例

//  群組-統(tǒng)一監(jiān)控一組任務(wù)
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_queue_t q = dispatch_get_global_queue(0, 0);
    // 添加任務(wù)
    // group 負(fù)責(zé)監(jiān)控任務(wù)测秸,queue 負(fù)責(zé)調(diào)度任務(wù)
    dispatch_group_async(group, q, ^{
        [NSThread sleepForTimeInterval:1.0];
        NSLog(@"任務(wù)1 %@", [NSThread currentThread]);
    });
    dispatch_group_async(group, q, ^{
        NSLog(@"任務(wù)2 %@", [NSThread currentThread]);
    });
    dispatch_group_async(group, q, ^{
        NSLog(@"任務(wù)3 %@", [NSThread currentThread]);
    });
   
    // 監(jiān)聽所有任務(wù)完成 - 等到 group 中的所有任務(wù)執(zhí)行完畢后疤估,"由隊列調(diào)度 block 中的任務(wù)異步執(zhí)行灾常!"
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        // 修改為主隊列,后臺批量下載做裙,結(jié)束后岗憋,主線程統(tǒng)一更新UI
        NSLog(@"OK %@", [NSThread currentThread]);
    });
    
    NSLog(@"come here");

64肃晚、視圖坐標(biāo)轉(zhuǎn)換

// 將像素point由point所在視圖轉(zhuǎn)換到目標(biāo)視圖view中锚贱,返回在目標(biāo)視圖view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
// 將像素point從view中轉(zhuǎn)換到當(dāng)前視圖中,返回在當(dāng)前視圖中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

// 將rect由rect所在視圖轉(zhuǎn)換到目標(biāo)視圖view中关串,返回在目標(biāo)視圖view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
// 將rect從view中轉(zhuǎn)換到當(dāng)前視圖中拧廊,返回在當(dāng)前視圖中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;

*例把UITableViewCell中的subview(btn)的frame轉(zhuǎn)換到
controllerA中
// controllerA 中有一個UITableView, UITableView里有多行UITableVieCell,cell上放有一個button
// 在controllerA中實(shí)現(xiàn):
CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];
// 此rc為btn在controllerA中的rect

或當(dāng)已知btn時:
CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];

65晋修、設(shè)置animation動畫終了吧碾,不返回初始狀態(tài)

animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

66、UIViewAnimationOptions類型

常規(guī)動畫屬性設(shè)置(可以同時選擇多個進(jìn)行設(shè)置)
UIViewAnimationOptionLayoutSubviews:動畫過程中保證子視圖跟隨運(yùn)動墓卦。
UIViewAnimationOptionAllowUserInteraction:動畫過程中允許用戶交互倦春。
UIViewAnimationOptionBeginFromCurrentState:所有視圖從當(dāng)前狀態(tài)開始運(yùn)行。
UIViewAnimationOptionRepeat:重復(fù)運(yùn)行動畫落剪。
UIViewAnimationOptionAutoreverse :動畫運(yùn)行到結(jié)束點(diǎn)后仍然以動畫方式回到初始點(diǎn)睁本。
UIViewAnimationOptionOverrideInheritedDuration:忽略嵌套動畫時間設(shè)置。
UIViewAnimationOptionOverrideInheritedCurve:忽略嵌套動畫速度設(shè)置忠怖。
UIViewAnimationOptionAllowAnimatedContent:動畫過程中重繪視圖(注意僅僅適用于轉(zhuǎn)場動畫)呢堰。  
UIViewAnimationOptionShowHideTransitionViews:視圖切換時直接隱藏舊視圖、顯示新視圖凡泣,而不是將舊視圖從父視圖移除(僅僅適用于轉(zhuǎn)場動畫)UIViewAnimationOptionOverrideInheritedOptions :不繼承父動畫設(shè)置或動畫類型枉疼。
2.動畫速度控制(可從其中選擇一個設(shè)置)
UIViewAnimationOptionCurveEaseInOut:動畫先緩慢,然后逐漸加速鞋拟。
UIViewAnimationOptionCurveEaseIn :動畫逐漸變慢骂维。
UIViewAnimationOptionCurveEaseOut:動畫逐漸加速。
UIViewAnimationOptionCurveLinear :動畫勻速執(zhí)行贺纲,默認(rèn)值席舍。
3.轉(zhuǎn)場類型(僅適用于轉(zhuǎn)場動畫設(shè)置,可以從中選擇一個進(jìn)行設(shè)置哮笆,基本動畫来颤、關(guān)鍵幀動畫不需要設(shè)置)
UIViewAnimationOptionTransitionNone:沒有轉(zhuǎn)場動畫效果。
UIViewAnimationOptionTransitionFlipFromLeft :從左側(cè)翻轉(zhuǎn)效果稠肘。
UIViewAnimationOptionTransitionFlipFromRight:從右側(cè)翻轉(zhuǎn)效果福铅。
UIViewAnimationOptionTransitionCurlUp:向后翻頁的動畫過渡效果。    
UIViewAnimationOptionTransitionCurlDown :向前翻頁的動畫過渡效果项阴。    
UIViewAnimationOptionTransitionCrossDissolve:舊視圖溶解消失顯示下一個新視圖的效果滑黔。    
UIViewAnimationOptionTransitionFlipFromTop :從上方翻轉(zhuǎn)效果笆包。    
UIViewAnimationOptionTransitionFlipFromBottom:從底部翻轉(zhuǎn)效果。

67略荡、獲取當(dāng)前View所在的控制器

#import "UIView+CurrentController.h"

@implementation UIView (CurrentController)

/** 獲取當(dāng)前View所在的控制器*/
-(UIViewController *)getCurrentViewController{
    UIResponder *next = [self nextResponder];
    do {
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        next = [next nextResponder];
    } while (next != nil); 
    return nil;
}

68庵佣、iOS橫向滾動的scrollView和系統(tǒng)pop手勢返回沖突的解決辦法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    // 首先判斷otherGestureRecognizer是不是系統(tǒng)pop手勢
    if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UILayoutContainerView")]) {
        // 再判斷系統(tǒng)手勢的state是began還是fail,同時判斷scrollView的位置是不是正好在最左邊
        if (otherGestureRecognizer.state == UIGestureRecognizerStateBegan && self.contentOffset.x == 0) {
            return YES;
        }
    }
    return NO;
}

69汛兜、設(shè)置狀態(tài)欄方向位置

修改狀態(tài)欄方向巴粪,
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

枚舉值說明:
UIDeviceOrientationPortraitUpsideDown,  //設(shè)備直立,home按鈕在上
UIDeviceOrientationLandscapeLeft,       //設(shè)備橫置粥谬,home按鈕在右
UIDeviceOrientationLandscapeRight,      //設(shè)備橫置, home按鈕在左
UIDeviceOrientationFaceUp,              //設(shè)備平放肛根,屏幕朝上
UIDeviceOrientationFaceDown             //設(shè)備平放,屏幕朝下

再實(shí)現(xiàn)這個代理方法就行了
- (BOOL)shouldAutorotate
{
    return NO; //必須返回no, 才能強(qiáng)制手動旋轉(zhuǎn)
}

69漏策、修改 UICollectionViewCell 之間的間距

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

70派哲,時間戳轉(zhuǎn)換成標(biāo)準(zhǔn)時間

-(NSString *)TimeStamp:(NSString *)strTime
{
    //因?yàn)闀r差問題要加8小時 == 28800 sec
    NSTimeInterval time=[strTime doubleValue]+28800;
    
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    
    //實(shí)例化一個NSDateFormatter對象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //設(shè)定時間格式,這里可以設(shè)置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    
    return currentDateStr;
}

71,CocoaPods 安裝不上怎么辦

終端進(jìn)入 repos目錄
cd ~/.cocoapods/repos
新建一個文件夾master
然后下載 https://coding.net/u/CocoaPods/p/Specs/git
到master下

72掺喻,快速創(chuàng)建Block

輸入 :xcode中輸入 : inlineblock

73芭届,Git 關(guān)聯(lián)倉庫 ,和基本配置

-------Git global setup-------

git config --global user.name "張大森"
git config --global user.email "zhangdasen@126.com"

-------Create a new repository-------
git clone git@gitlab.testAddress.com:test/QRZxing.git
cd QRZxing
touch README.mdgit
add README.mdgit commit -m "add README"
git push -u origin master

-------Existing folder or Git repository-------
cd existing_folder
git init
git remote add origin git@gitlab.testAddress.com:test/QRZxing.git
git add .
git commit
git push -u origin master

74,Git 命令大全

75,編譯器優(yōu)化級別
GCC_OPTIMIZATION_LEVEL

None: 不做優(yōu)化使用這個設(shè)置感耙,編譯器的目標(biāo)是減少編譯成本褂乍,使調(diào)試產(chǎn)生預(yù)期的結(jié)果。
Fast:優(yōu)化編譯將為大函數(shù)占用更多的時間和內(nèi)存使用這個設(shè)置抑月,編譯器將嘗試減少代碼的大小和執(zhí)行時間树叽,不進(jìn)行任何優(yōu)化,需要大量編譯時間谦絮。
Faster:編譯器執(zhí)行幾乎所有支持的優(yōu)化题诵,它不考慮空間和速度之間的平衡與“Fast”設(shè)置相比,該設(shè)置會增加編譯時間和生成代碼的性能层皱。編譯器不進(jìn)行循環(huán)展開性锭、內(nèi)聯(lián)函數(shù)和寄存器變量的重命名。
Fastest:開啟“Faster”支持的所有的優(yōu)化叫胖,同時也開啟內(nèi)聯(lián)函數(shù)和寄存器變量的重命名選項
Fastest,smallest:優(yōu)化代碼大小這個設(shè)置啟用“Faster”所有的優(yōu)化草冈,一般不增加代碼大小,它還執(zhí)行旨在減小代碼大小的進(jìn)一步優(yōu)化瓮增。

76怎棱,獲取本機(jī)DNS服務(wù)器,根據(jù)域名獲取IP

/// 獲取本機(jī)DNS服務(wù)器
- (NSString *)outPutDNSServers
{
    res_state res = malloc(sizeof(struct __res_state));
    
    int result = res_ninit(res);
    
    NSMutableArray *dnsArray = @[].mutableCopy;
    
    if ( result == 0 )
    {
        for ( int i = 0; i < res->nscount; i++ )
        {
            NSString *s = [NSString stringWithUTF8String :  inet_ntoa(res->nsaddr_list[i].sin_addr)];
            
            [dnsArray addObject:s];
        }
    }
    else{
        NSLog(@"%@",@" res_init result != 0");
    }
    
    res_nclose(res);
    
    return dnsArray.firstObject;
}

/// 根據(jù)域名獲取IP地址
- (NSString*)getIPWithHostName:(const NSString*)hostName
{
    const char *hostN= [hostName UTF8String];
    
    // 記錄主機(jī)的信息绷跑,包括主機(jī)名拳恋、別名、地址類型砸捏、地址長度和地址列表 結(jié)構(gòu)體
    struct hostent *phot;
    
    @try {
        // 返回對應(yīng)于給定主機(jī)名的包含主機(jī)名字和地址信息的hostent結(jié)構(gòu)指針
        phot = gethostbyname(hostN);

        struct in_addr ip_addr;
        
        memcpy(&ip_addr, phot->h_addr_list[0], 4);
        
        char ip[20] = {0};
     
        inet_ntop(AF_INET, &ip_addr, ip, sizeof(ip));
        
        NSString* strIPAddress = [NSString stringWithUTF8String:ip];
        
        return strIPAddress;
        
    }
        @catch (NSException *exception) {
            return nil;
    }
}

77谬运,獲取當(dāng)前wifi連接信息

- (void)viewDidLoad {
    [super viewDidLoad];
    
    id info = nil;
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    for (NSString *ifnam in ifs) {
        info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        NSString *str = info[@"SSID"];
        NSString *str2 = info[@"BSSID"];
        NSString *str3 = [[ NSString alloc] initWithData:info[@"SSIDDATA"] encoding:NSUTF8StringEncoding];
    
        NSLog(@"%@ %@ %@",str,str2,str3);
    }

以上整理只為自己和大家方便查看隙赁,iOS中小技巧和黑科技數(shù)不盡
如果大家有不錯的代碼和技巧,也可留言或私信我梆暖,然后加上伞访。
待續(xù)。轰驳。厚掷。。滑废。蝗肪。
會繼續(xù)更新的! ??

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末袜爪,一起剝皮案震驚了整個濱河市蠕趁,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌辛馆,老刑警劉巖俺陋,帶你破解...
    沈念sama閱讀 218,941評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異昙篙,居然都是意外死亡腊状,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評論 3 395
  • 文/潘曉璐 我一進(jìn)店門苔可,熙熙樓的掌柜王于貴愁眉苦臉地迎上來缴挖,“玉大人,你說我怎么就攤上這事焚辅∮澄荩” “怎么了?”我有些...
    開封第一講書人閱讀 165,345評論 0 356
  • 文/不壞的土叔 我叫張陵同蜻,是天一觀的道長棚点。 經(jīng)常有香客問我,道長湾蔓,這世上最難降的妖魔是什么瘫析? 我笑而不...
    開封第一講書人閱讀 58,851評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮默责,結(jié)果婚禮上贬循,老公的妹妹穿的比我還像新娘。我一直安慰自己桃序,他們只是感情好杖虾,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,868評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著葡缰,像睡著了一般亏掀。 火紅的嫁衣襯著肌膚如雪忱反。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,688評論 1 305
  • 那天滤愕,我揣著相機(jī)與錄音温算,去河邊找鬼。 笑死间影,一個胖子當(dāng)著我的面吹牛注竿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播魂贬,決...
    沈念sama閱讀 40,414評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼巩割,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了付燥?” 一聲冷哼從身側(cè)響起宣谈,我...
    開封第一講書人閱讀 39,319評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎键科,沒想到半個月后闻丑,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,775評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡勋颖,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年嗦嗡,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片饭玲。...
    茶點(diǎn)故事閱讀 40,096評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡侥祭,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出茄厘,到底是詐尸還是另有隱情矮冬,我是刑警寧澤,帶...
    沈念sama閱讀 35,789評論 5 346
  • 正文 年R本政府宣布蚕断,位于F島的核電站欢伏,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏亿乳。R本人自食惡果不足惜硝拧,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,437評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望葛假。 院中可真熱鬧障陶,春花似錦、人聲如沸聊训。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,993評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽带斑。三九已至鼓寺,卻和暖如春勋拟,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背妈候。 一陣腳步聲響...
    開封第一講書人閱讀 33,107評論 1 271
  • 我被黑心中介騙來泰國打工敢靡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人苦银。 一個月前我還...
    沈念sama閱讀 48,308評論 3 372
  • 正文 我出身青樓啸胧,卻偏偏與公主長得像,于是被迫代替她去往敵國和親幔虏。 傳聞我的和親對象是個殘疾皇子纺念,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,037評論 2 355

推薦閱讀更多精彩內(nèi)容