xCode8以及iOS10 的新特性

其余: ios10中 适配问题(1.系统判断方法失效;2.隐私数据的访问问题;3.UIColor 问题4.真彩色的显示5.ATS问题6.UIStatusBar问题7.UITextField8.UserNotifications(用户通知)9.UICollectionViewCell的的优化php

 

原址:  http://www.cnblogs.com/jiangshengkai/p/5880872.htmlhtml

 

1.Xcode8 欢迎界面ios

 

        欢迎界面扁平化网格去掉,是否是好看不少了?git


 

2.建立工程更加人性化程序员

        经常使用的放在最前面github

 

  • 1.内置表情包(Sticker Packs)
    • 能够经过在Xcode中新建Sticker Pack Application来建立。这种方式能够简单地经过添加图片来在iMessage中添加表情包。添加的贴纸须要知足一下条件
    • 图片类型必须是 png、apng、gif或者jpeg
    • 文件大小必须 小于500K
    • 图片大小必须在 100 100 到 206 206 之间
    • 须要注意的是:必需要永远提供 @3x 大小的图片(即 300 300 到 618 618 )。系统能够根据当前设备经过 runtime 自动调整图片来呈现@2x 和 @1x
    • 系统可以自适应的展现贴纸,因此为了更好的展现贴纸,最好提供的贴纸是如下三种大小的类型
    • 小型 100100
    • 中型 136136
    • 大型 206*206
  • 2.iMessage应用
    • iMessage app使用完整的框架和Message app进行交互。使用iMessage app可以
    • 在消息应用内呈现一个自定义的用户交互界面。 使用MSMessagesAppViewController
    • 建立一个自定义或者动态的表情包浏览器。使用 MSStickerBrowserViewController
    • 添加文本、表情、或者媒体文件到消息应用的文本输入框。使用 MSConversation
    • 建立带有特定的应用数据交互的消息。使用 MSMessage
    • 更新能够相互影响的消息(例如,建立游戏或者能够合做的应用)。

 

3.类名提示web

         从Xcode8beta1就支持类名提示了,因此Xcode8正式版也支持类名提示,大家在也不用忧伤了浏览器

 

4.Swift3.0 and Swift2.3 随意切换性能优化

        值得一提的是Xcode8.0并无作语法捆绑,在以往的版本中都是捆绑最新的语法网络

        PS:苹果愈来愈开放

 

默认状况:


 

Swift3.0


Swift2.3


语法转换

 

固然Swift只能向上兼容,不能向下兼容,若是你的语法是2.3的能够转换为3.0的,可是转换不必定成功

 

 

5.控制台输出

       控制台是你们最长用的从Xcode8beta1 OC控制台不NSLog不输出,到之后控制台都输出一大堆系统信息等等,你们很烦,例如:

 

 

按照以下方式,能够禁止这些没必要要的信息输出:修改对应的属性,禁止系统的输出日志


 


 

 

     禁止后的效果以下,咱们本身输出的东西依然能够正常输出


 

6.字体改变

      字体改变,对于那些强迫症的程序员来讲简直就是福音,Xcode8中用的字体是San Francisco Mono字体

 

 

 

7.代码高亮当前行,看上图

8.代码调试支持Runtime

Xcode8新增Runtime调试,界面能够展现运行时的问题,改善的界面调试对于调试不清晰或者不满意的布局变的更简单

 

 

 

9代码签名

        Xcode8以后必须用代码签名,包括第三方SDK也须要代码签名,好的一点是苹果提供自动代码签名

 

 

10.文档

文档面目一新,分为Swift 和OC文档,具体看图



 

一.代码及Api注意

使用Xcode8以后,有些代码可能就编译不过去了,具体我就说说我碰到的问题。

 

1.UIWebView的代理方法:

//注⚠️:新版本的这个问题已经解决  系统生成中已经没有nullable 

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 

**注意要删除NSError前面的 nullable,不然报错。

//原来的方法   - (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error { [self hideHud]; }

二。权限以及相关设置

注意,添加的时候,末尾不要有空格
咱们须要打开info.plist文件添加相应权限的说明,不然程序在iOS10上会出现崩溃。
具体以下图:


QQ20160914-0.png

麦克风权限:Privacy - Microphone Usage Description 是否容许此App使用你的麦克风?
相机权限: Privacy - Camera Usage Description 是否容许此App使用你的相机?
相册权限: Privacy - Photo Library Usage Description 是否容许此App访问你的媒体资料库?通信录权限: Privacy - Contacts Usage Description 是否容许此App访问你的通信录?
蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?

语音转文字权限:Privacy - Speech Recognition Usage Description 是否容许此App使用语音识别?
日历权限:Privacy - Calendars Usage Description 是否容许此App使用日历?

定位权限:Privacy - Location When In Use Usage Description 咱们须要经过您的地理位置信息获取您周边的相关数据
定位权限: Privacy - Location Always Usage Description 咱们须要经过您的地理位置信息获取您周边的相关数据
定位的须要这么写,防止上架被拒。


三。更新Xcode8以后,新创建工程,都会打印一堆莫名其妙看不懂的Log.

如这些

subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1,

屏蔽的方法以下:
Xcode8里边 Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加
OS_ACTIVITY_MODE = Disable


若是写了以后仍是打印log,请从新勾选对勾,就能够解决了

 

四。Notification(通知)

自从Notification被引入以后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至如今iOS 10开始真正的进行大改重构,这让开发者也体会到UserNotifications的易用,功能也变得很是强大。

  • iOS 9 之前的通知

    1.在调用方法时,有些方法让人很难区分,容易写错方法,这让开发者有时候很苦恼。

    2.应用在运行时和非运行时捕获通知的路径还不一致。

    3.应用在前台时,是没法直接显示远程通知,还须要进一步处理。

    4.已经发出的通知是不能更新的,内容发出时是不能改变的,而且只有简单文本展现方式,扩展性根本不是很好。

  • iOS 10 开始的通知

    1.全部相关通知被统一到了UserNotifications.framework框架中。

    2.增长了撤销、更新、中途还能够修改通知的内容。

    3.通知不在是简单的文本了,能够加入视频、图片,自定义通知的展现等等。

    4.iOS 10相对以前的通知来讲更加好用易于管理,而且进行了大规模优化,对于开发者来讲是一件好事。

    5.iOS 10开始对于权限问题进行了优化,申请权限就比较简单了(本地与远程通知集成在一个方法中)。

  • iOS 10 通知学习相关资料:

    UserNotifications: 苹果官方文档 - 苹果官方视频1 - 苹果官方视频2 - 苹果官方视频3
    活久见的重构 - iOS 10 UserNotifications 框架解析
    WWDC2016 Session笔记 - iOS 10 推送Notification新特性


五。ATS的问题

iOS 9中默认非HTTS的网络是被禁止的,固然咱们也能够把NSAllowsArbitraryLoads设置为YES禁用ATS。不过iOS 10从2017年1月1日起苹果不容许咱们经过这个方法跳过ATS,也就是说强制咱们用HTTPS,若是不这样的话提交App可能会被拒绝。可是咱们能够经过NSExceptionDomains来针对特定的域名开放HTTP能够容易经过审核。

参考学习文章以下:
关于 iOS 10 中 ATS 的问题

六。iOS 10 UICollectionView 性能优化

随着开发者对UICollectionView的信赖,项目中用的地方也比较多,可是仍是存在一些问题,好比有时会卡顿、加载慢等。因此iOS 10 对UICollectionView进一步的优化,由于叙述起来比较复杂耗费时间,在这里只提供学习参考文章以下:
WWDC2016 Session笔记 - iOS 10 UICollectionView新特性

 

七.iOS 10 UIColor 新增方法

如下是官方文档的说明:

Most graphics frameworks throughout the system, including Core Graphics, Core Image, Metal, and AVFoundation, have substantially improved support for extended-range pixel formats and wide-gamut color spaces. By extending this behavior throughout the entire graphics stack, it is easier than ever to support devices with a wide color display. In addition, UIKit standardizes on working in a new extended sRGB color space, making it easy to mix sRGB colors with colors in other, wider color gamuts without a significant performance penalty.

Here are some best practices to adopt as you start working with Wide Color.

  • In iOS 10, the UIColor class uses the extended sRGB color space and its initializers no longer clamp raw component values to between 0.0 and 1.0. If your app relies on UIKit to clamp component values (whether you’re creating a color or asking a color for its component values), you need to change your app’s behavior when you link against iOS 10.
  • When performing custom drawing in a UIView on an iPad Pro (9.7 inch), the underlying drawing environment is configured with an extended sRGB color space.
  • If your app renders custom image objects, use the new UIGraphicsImageRenderer class to control whether the destination bitmap is created using an extended-range or standard-range format.
  • If you are performing your own image processing on wide-gamut devices using a lower level API, such as Core Graphics or Metal, you should use an extended range color space and a pixel format that supports 16-bit floating-point component values. When clamping of color values is necessary, you should do so explicitly.
  • Core Graphics, Core Image, and Metal Performance Shaders provide new options for easily converting colors and images between color spaces.

由于以前咱们都是用RGB来设置颜色,反正用起来也不是特别多样化,此次新增的方法应该就是一个弥补吧。因此在iOS 10 苹果官方建议咱们使用sRGB,由于它性能更好,色彩更丰富。若是你本身为UIColor写了一套分类的话也可尝试替换为sRGBUIColor类中新增了两个Api以下:

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

八.iOS 10 UITextContentType

// The textContentType property is to provide the keyboard with extra information about the semantic intent of the text document. @property(nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0); // default is nil

在iOS 10 UITextField添加了textContentType枚举,指示文本输入区域所指望的语义意义。

使用此属性能够给键盘和系统信息,关于用户输入的内容的预期的语义意义。例如,您能够指定一个文本字段,用户填写收到一封电子邮件确认uitextcontenttypeemailaddress。当您提供有关您指望用户在文本输入区域中输入的内容的信息时,系统能够在某些状况下自动选择适当的键盘,并提升键盘修正和主动与其余文本输入机会的整合。

九.iOS 10 字体随着手机系统字体而改变

当咱们手机系统字体改变了以后,那咱们Applabel也会跟着一块儿变化,这须要咱们写不少代码来进一步处理才能实现,可是iOS 10 提供了这样的属性adjustsFontForContentSizeCategory来设置。由于没有真机,具体实际操做还没去实现,若是理解错误帮忙指正。

UILabel *myLabel = [UILabel new]; /* UIFont 的preferredFontForTextStyle: 意思是指定一个样式,并让字体大小符合用户设定的字体大小。 */ myLabel.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline]; /* Indicates whether the corresponding element should automatically update its font when the device’s UIContentSizeCategory is changed. For this property to take effect, the element’s font must be a font vended using +preferredFontForTextStyle: or +preferredFontForTextStyle:compatibleWithTraitCollection: with a valid UIFontTextStyle. */ //是否更新字体的变化 myLabel.adjustsFontForContentSizeCategory = YES;

十.iOS 10 UIScrollView新增refreshControl


 

iOS 10 之后只要是继承UIScrollView那么就支持刷新功能:

@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;

11.iOS 10 判断系统版本正确姿式

判断系统版本是咱们常常用到的,尤为是如今你们都有可能须要适配iOS 10,那么问题就出现了,以下图:


 

咱们获得了答案是:

//值为 1 [[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue] //值为10.000000 [[UIDevice currentDevice] systemVersion].floatValue, //值为10.0 [[UIDevice currentDevice] systemVersion]

因此说判断系统方法最好仍是用后面的两种方法,哦~我忘记说了[[UIDevice currentDevice] systemVersion].floatValue这个方法也是不靠谱的,好像在8.3版本输出的值是8.2,记不清楚了反正是不靠谱的,因此建议你们用[[UIDevice currentDevice] systemVersion]这个方法!

相关文章
相关标签/搜索