挑燈夜戰(zhàn),同步更新iOS10開發(fā),讓學(xué)員學(xué)習(xí)最前沿的技術(shù)

那么在前兩天我的Xcode 8.0新特性和iOS10.0開發(fā)分享后,短短的時間吸引了很多粉絲,于是我更加堅定要努力,不辜負(fù)更多人的期望,經(jīng)常這一兩天挑燈夜戰(zhàn)的精心準(zhǔn)備,現(xiàn)在將整理出來的iOS10開發(fā)的最新知識和心得體會再次分享給大家,讓我們小碼哥每一個學(xué)員都能時刻站在IT界最新的前沿上,學(xué)習(xí)到最新最潮的技術(shù)!
網(wǎng)盤地址: http://pan.baidu.com/s/1i45UWN7 密碼:cvr5
蘋果在本地的WWDC結(jié)束之后呢,像開發(fā)者推送了iOS10系統(tǒng),雖然是beta版,但是熱愛技術(shù)人總是不會停止腳步去研究去學(xué)習(xí),這次更新主要表現(xiàn)在以下這幾個方面。
1.語音識別
  蘋果官方在文檔中新增了API Speech,那么在以前我們處理語音識別非常的繁瑣甚至很多時候可能需要借助于第三方框架處理,那么蘋果推出了這個后,我們以后處理起來就非常的方便了,speech具有以下特點:
可以實現(xiàn)連續(xù)的語音識別
可以對語 音文件或者語音流進(jìn)行識別
最佳化自由格式的聽寫(可理解為多語言支持)和搜索式的字符串
官方文檔:

1466240218186284.gif

1466238466310689.png

核心代碼:

  #import <Speech/Speech.h>
    //1.創(chuàng)建本地化標(biāo)識符
    NSLocale *local =[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
     //2.創(chuàng)建一個語音識別對象
    SFSpeechRecognizer *sf =[[SFSpeechRecognizer alloc] initWithLocale:local];
     
    //3.將bundle 中的資源文件加載出來返回一個url
     
    NSURL *url =[[NSBundle mainBundle] URLForResource:@"游子吟.mp3" withExtension:nil];
    //4.將資源包中獲取的url 傳遞給 request 對象
    SFSpeechURLRecognitionRequest *res =[[SFSpeechURLRecognitionRequest alloc] initWithURL:url];
     
    //5.發(fā)送一個請求
    [sf recognitionTaskWithRequest:res resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
        if (error!=nil) {
            NSLog(@"語音識別解析失敗,%@",error);
        }
        else
        {
            //解析正確
            NSLog(@"---%@",result.bestTranscription.formattedString);
        }
    }];

語音識別同樣的需要真機進(jìn)行測試 ,因為需要硬件的支持,還需要訪問權(quán)限

2.UITabBarController 中的改進(jìn)
  在iOS 10之前,tabBarItem上的文字顏色,默認(rèn)是 藍(lán)色,上面的新消息提醒數(shù)字badge 默認(rèn)是紅色的,未選中的TabBarItem的文字顏色默認(rèn)是黑色的,我們修改的話,也只能修改它的默認(rèn)顏色 ,其它的就不能進(jìn)行個性化定制,使用起來非常的不方便,iOS10之后我們可以輕松個性化定制了。
核心代碼:

//1.創(chuàng)建出三個UIViewcontroller 對象
     
    OneViewController *oneVc =[[OneViewController alloc] init];
     
    //2.設(shè)置每一個控制器上的tabbar
    oneVc.view.backgroundColor =[UIColor redColor];
     
   
     
     
    //設(shè)置標(biāo)題
    oneVc.tabBarItem.title = @"首頁";
     
     
     
    TwoViewController *twovC =[[TwoViewController alloc] init];
     
    twovC.view.backgroundColor =[UIColor purpleColor];
     
     
      //設(shè)置標(biāo)題
    twovC.tabBarItem.title = @"圈子";
    ThreeViewController *threVC =[[ThreeViewController alloc] init];
    threVC.view.backgroundColor =[UIColor blueColor];
     
      //設(shè)置標(biāo)題
    threVC.tabBarItem.title = @"社交";
     
     
    //2.將創(chuàng)建好的三個普通控制器加入到tabbarController 控制器中
     
    [self addChildViewController:oneVc];
     
    [self addChildViewController:twovC];
    [self addChildViewController:threVC];
     
     
     
    //改變tabbar 上面的文字默認(rèn)顏色
     
    oneVc.tabBarController.tabBar.tintColor =[UIColor yellowColor];
     
        twovC.tabBarController.tabBar.tintColor =[UIColor yellowColor];
     
        threVC.tabBarController.tabBar.tintColor =[UIColor yellowColor];
     
     
    //使用iOS 10新推出的 修改 tabbar 未選中的tintColor 顏色
     
    //這一句代碼將 tabbar 未選中的時候的默認(rèn)色- 黑色改為紅色
     
    oneVc.tabBarController.tabBar.unselectedItemTintColor =[UIColor redColor];
     
     
    //tabbarItem 中屬性
     
    //數(shù)字提醒的顏色  在iOS 10之前的版本默認(rèn)都是數(shù)字提醒都是紅色
    oneVc.tabBarItem.badgeColor =[UIColor orangeColor];
    oneVc.tabBarItem.badgeValue =@"90";
     
    //將tabBarItem 中數(shù)字提醒默認(rèn)的白色改掉  使用富文本修改
    [oneVc.tabBarItem setBadgeTextAttributes:@{
                                               NSForegroundColorAttributeName:[UIColor blackColor]
                                               } forState:UIControlStateNormal];

效果圖:


1466240218186284.gif

3.iOS10.0中字體跟隨系統(tǒng)設(shè)置變化大小

在以前如果說我們想改變APP中程序的字體大小,我們只能自定義字體或者使用runtime進(jìn)行處理,或者都得設(shè)置UIFont,非常的不妨百年,從iOS 10蘋果官方允許我們自定義設(shè)置
核心代碼:

/*
      在iOS 10當(dāng)中,當(dāng)咱們用戶將手機的字體大小進(jìn)行了設(shè)置調(diào)整之后,那么app中設(shè)置相關(guān)代碼字體也會跟著一起變化 ,支持常見一些字體UI控件 比如uilabel uibutton
     **/
    [super viewDidLoad];
     
    //設(shè)置字體的改變大小
    self.labels.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    //允許改變
     
    /*
       蘋果官方明確的告訴你必須和  preferredFontForTextStyle 或者preferredFontForTextStyle:(NSString *)style compatibleWithTraitCollection 進(jìn)行結(jié)合使用
       注意這里不支持模擬器操作
     **/
     
    self.labels.adjustsFontForContentSizeCategory = YES;
  1. UIViewPropertyAnimator屬性動畫器

那么在iOS 10之前,我們使用UIView 做動畫效果或者自定義一些layer 的動畫,如果開始了,一般無法進(jìn)行停止操作更不能暫停操作,而且一些非常復(fù)雜的動畫處理也比較麻煩,但是在iOS10,蘋果退出了一個全新的API UIViewPropertyAnimator,可供我們處理動畫操作

UIViewPropertyAnimator 是 iOS 10 中新增的一個執(zhí)行 View 動畫的類,具有以下特點:
   可中斷性
   可擦除
  可反轉(zhuǎn)性
  豐富的動畫時間控制功能

官方文檔:


1466239501935855.png

1466239557221183.png

核心代碼:

#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIView *myView;
@property(nonatomic,strong)UIViewPropertyAnimator *myViewPro;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
     
    //1.創(chuàng)建一個View對象
    UIView *Views =[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    Views.backgroundColor =[UIColor yellowColor];
    [self.view addSubview:Views];
    //2.創(chuàng)建一個外部的變量進(jìn)行引用
     
    self.myView = Views;
     
     
    //3.創(chuàng)建一個view 動畫器
    UIViewPropertyAnimator *viewPro  =[UIViewPropertyAnimator runningPropertyAnimatorWithDuration:1.0 delay:30.0 options:UIViewAnimationOptionCurveLinear animations:^{
        //使用View動畫器修改View的frame
        self.myView.frame = CGRectMake(230, 230, 130, 130);
    } completion:nil];
     
    self.myViewPro = viewPro;
}
//結(jié)束
- (IBAction)stop:(id)sender {
     
    // YES 和NO 適用于設(shè)置當(dāng)前這個屬性動畫器是否可以繼續(xù)使用
    [self.myViewPro stopAnimation:YES];
}
//繼續(xù)
- (IBAction)continued:(id)sender {
     
     
    //UITimingCurveProvider
    /**
    @property(nullable, nonatomic, readonly) UICubicTimingParameters *cubicTimingParameters;
    @property(nullable, nonatomic, readonly) UISpringTimingParameters *springTimingParameters;
      
     **/
    //設(shè)置彈簧效果 DampingRatio取值范圍是 0-1
     
    //這個取值 決定彈簧抖動效果 的大小 ,越往  0 靠近那么就越明顯
    UISpringTimingParameters *sp =[[UISpringTimingParameters alloc] initWithDampingRatio:0.01];
     
    //設(shè)置一個動畫的效果
//    UICubicTimingParameters *cub =[[UICubicTimingParameters alloc] initWithAnimationCurve:UIViewAnimationCurveEaseInOut];
     
     //durationFactor  給一個默認(rèn)值 1就可以
    [self.myViewPro continueAnimationWithTimingParameters:sp durationFactor:1.0];
}
//暫停
- (IBAction)puase:(id)sender {
     
    [self.myViewPro pauseAnimation];
}
//開始
- (IBAction)start:(id)sender {
     
    [self.myViewPro startAnimation];
}

效果圖:


1466241456100066.png

5.UIColor 新增方法

在iOS10之前,UIColor中設(shè)置顏色只能通過RGB 來表示,在iOS原生還不支持#16進(jìn)制寫法,還得自己寫分類去處理,我們知道RGB表示的顏色是優(yōu)先的,而且也是不精準(zhǔn)的,那么在iOS10中,蘋果官方新增了colorWithDisplayP3Red方法

關(guān)鍵代碼:

+ (
UIColor
 *)colorWithDisplayP3Red:(
CGFloat
)displayP3Red green:(
CGFloat
)green blue:(
CGFloat
)blue alpha:(
CGFloat
)alpha 
NS_AVAILABLE_IOS
(
10
_0);

6.UIApplication對象中openUrl被廢棄

在iOS 10.0以前的年代,我們要想使用應(yīng)用程序去打開一個網(wǎng)頁或者進(jìn)行跳轉(zhuǎn),直接使用[[UIApplication sharedApplication] openURL 方法就可以了,但是在iOS 10 已經(jīng)被廢棄了,因為使用這種方式,處理的結(jié)果我們不能攔截到也不能獲取到,對于開發(fā)是非常不利的,在iOS 10全新的退出了 [[UIApplication sharedApplication] openURL:nil options:nil completionHandler:nil];有一個成功的回調(diào)block 可以進(jìn)行監(jiān)視。

蘋果官方解釋:

   //說明在iOS 10.0中openUrl方法已經(jīng)廢棄了 改為openURL:nil options:nil completionHandler:^(BOOL success
    /*
     // Options are specified in the section below for openURL options. An empty options dictionary will result in the same
     // behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather
     // than returning a result.
     // The completion handler is called on the main queue.

關(guān)鍵代碼:

  [[UIApplication sharedApplication] openURL:nil options:nil completionHandler:^(BOOL success) {
         
    }];

當(dāng)然除了以上的這些,其它的還有很多,比如下面這些

  1. SiriKit

在 iOS 10 里面開發(fā)者可以使用 Siri SDK,毫無疑問這也是 iOS 10 最重要的 SDK。從此開發(fā)者可以使用原生API提供語音搜索、語音轉(zhuǎn)文字消息甚至更多常見語音功能。

  1. User Notifications

這個 API 讓你可以處理本地或遠(yuǎn)程的用戶通知,并且可以基于某個條件,例如時間或者地理位置。這個異常強大,貌似可以攔截并替換自己 app 發(fā)下來的 payload,并且在之前版本SDK的本地通知框架已經(jīng)被廢棄了,在上一篇帖子有所講到以及代碼都有展示。

8.CallKit

繼2014年蘋果推出VoIP證書后,這次VoIP 接口的開放,以及一個全新的 App Extension,簡直是VOIP的福音,可見蘋果對VOIP的重視。callkit框架 VoIP應(yīng)用程序集成與iPhone的用戶界面,給用戶一個很棒的經(jīng)歷。用這個框架來讓用戶查看和接聽電話的鎖屏和VoIP管理聯(lián)系人電話在手機APP的收藏夾和歷史的觀點。
callkit還介紹了應(yīng)用程序的擴展,使呼叫阻塞和來電識別。您可以創(chuàng)建一個應(yīng)用程序擴展,可以將一個電話號碼與一個名稱聯(lián)系起來,或者告訴系統(tǒng)當(dāng)一個號碼應(yīng)該被阻止。

9.第三方鍵盤的改進(jìn)

非常非常重要,第三方鍵盤一直都不能很方便的擁有長按地球鍵的功能,現(xiàn)在有了。通過 handleInputModeListFromView:withEvent: 可以彈出系統(tǒng)鍵盤列表。同時使用 documentInputMode 可以檢測輸入上下文中的語言,你可以對輸入方式進(jìn)行一些類似于對齊方式的調(diào)整。
10.iOS10 對隱私權(quán)限的管理
  比如訪問的攝像頭、麥克風(fēng)等硬件,都需要提前請求應(yīng)用權(quán)限、允許后才可以使用,或者現(xiàn)在要提前聲明,雖然以往要求不嚴(yán)格。在iOS10中比如遇到崩潰,日志:
崩潰日志:
***This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
你需要在info.plist文件 添加一個“NSContactsUsageDescription ”的Key,Value添加一個描述。

1466241456100066.png

視頻播放 需要在info.Plist中配置
官方解釋:This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSAppleMusicUsageDescription key with a string value explaining to the user how the app uses this data.
訪問用戶的隱私數(shù)據(jù),并且沒有向用戶說明,必須在plist(info.plist)中配置這個key NSAppleMusicUsageDescription 并且向用戶說明.


1466242673131982.png

11.Xcode7 和Xcode 8項目中的xib兼容問題
  在Xcode8上打開項目要小心,尤其是對于xib過程,在變動后可不要隨意點保存,否則當(dāng)你回頭用Xcode7打開時時發(fā)現(xiàn)報錯了,Xcode保存的xib在xcode7上是識別不了的!

12.APPlePlay(蘋果支付)
  可用于 SFSafariViewController
  可用于沒有UI的extensions中
  在 iMessage 應(yīng)用中也支持 ApplePay

13.CoreData提升了并發(fā)訪問性能

14.刷新控件(UIRefresh Control)
iOS系統(tǒng)自帶的刷新控件支持所有的 UIScrollView 以及其子類,比如說 UICollectionView,UITableView。
核心代碼:

    
//
//  UIRefreshControlHosting.h
//  UIKit
//
//  Copyright 2016 Apple Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@class UIRefreshControl;
NS_CLASS_AVAILABLE_IOS(10_0) @protocol UIRefreshControlHosting <NSObject>
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl __TVOS_PROHIBITED;
@end

15.GCD多線程支持創(chuàng)建私有隊列

iOS課程更新

來源:
http://bbs.520it.com/forum.php?mod=viewthread&tid=703&extra=page%3D1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容