iOS10资料和Xcode8的新特性和坑<二>

一、iOS 10中UIstatusBar方法过期:


iOS10资料和Xcode8的新特性和坑<二>_第1张图片

在我们开发中 有可能用到UIStatusBar的一些属性,在iOS 10中这些方法已经过期不能使用,如果你的项目中有用的话就得需要适配。通过上面的图片也可以发现,如果在iOS 10中你需要使用preferredStatusBar比如以下:

iOS 10- (UIStatusBarStyle)preferredStatusBarStyle {returnUIStatusBarStyleDefault;

}

二、iOS 10 中UICollectionView的性能优化

随着我们开发者对UICollectionVIew的信赖,项目当中用得到的地方特别多,但是还是存在一些问题,比如卡顿,加载缓慢等。所以iOS10对UICollectionView进行了进一步的优化,主要体现在了三个方面:1、顺滑的滑动体验:只要加入少量的代码就能够实现。2、针对self-sizing的改进:self-sizing的API在iOS8的时候被引进,iOS10中加入更多特性是cell更加容易去适配;3、interactive-reordering重拍:在iOS9中重点介绍过了,在iOS10的API里面大大增强了这一功能。就到这里这三点在复杂就不一一介绍了看连接: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写了一套分类的话也可尝试替换为sRGB,UIColor类中新增了两个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 字体随着手机系统字体而改变

当我们手机系统字体改变了之后,那我们App的label也会跟着一起变化,这需要我们写很多代码来进一步处理才能实现,但是iOS 10 提供了这样的属性adjustsFontForContentSizeCategory来设置。因为没有真机,具体实际操作还没去实现,如果理解错误帮忙指正。

UILabel*myLabel = [UILabelnew];/*

UIFont 的preferredFontForTextStyle: 意思是指定一个样式,并让字体大小符合用户设定的字体大小。

*/myLabel.font=[UIFontpreferredFontForTextStyle: 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


iOS10资料和Xcode8的新特性和坑<二>_第2张图片

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

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

七、iOS 10 判断系统版本正确姿势

判断系统版本是我们经常用到的,尤其是现在大家都有可能需要适配iOS 10,那么问题就出现了,如下图:


iOS10资料和Xcode8的新特性和坑<二>_第3张图片

我们得到了答案是:

//值为 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]这个方法!

Swift判断如下:

if#available(iOS 10.0, *) {// iOS 10.0print("iOS 10.0");              }else{ }

参考文章如下:

iOS 日常工作之常用宏定义大全

八、Xcode 8 插件不能用的问题

大家都升级了Xcode 8,但是对于插件依赖的开发者们,一边哭着一边去网上寻找解决办法。那么下面是解决办法:

让你的 Xcode8 继续使用插件

但是看到文章最后的解释,我们知道如果用插件的话,可能安全上会有问题、并且提交审核会被拒绝,所以建议大家还是不要用了,解决办法总是有的,比如在Xcode中添加注释的代码块也是很方便的。

九、iOS 10开始项目中有的文字显示不全问题

我用Xcode 8 和Xcode 7.3分别测试了下,如下图:


iOS10资料和Xcode8的新特性和坑<二>_第4张图片
iOS10资料和Xcode8的新特性和坑<二>_第5张图片

创建一个Label然后让它自适应大小,字体大小都是17最后输出的宽度是不一样的,我们再看一下,下面的数据就知道为什么升级iOS 10 之后App中有的文字显示不全了:

Xcode 8打印                                       Xcode 7.3打印

1个文字宽度:17.5                           1个文字宽度:17

2个文字宽度:35                               2个文字宽度:34

3个文字宽度:52                               3个文字宽度:51

4个文字宽度:69.5                            4个文字宽度:68

5个文字宽度:87                                5个文字宽度:85

6个文字宽度:104                              6个文字宽度:102

7个文字宽度:121.5                           7个文字宽度:119

8个文字宽度:139                               8个文字宽度:136

9个文字宽度:156                               9个文字宽度:153

10个文字宽度:173.5                         10个文字宽度:170

英文字母会不会也有这种问题,我又通过测试,后来发现英文字母没有问题,只有汉字有问题。目前只有一个一个修改控件解决这个问题,暂时没有其他好办法来解决。

十、Xcode 8使用Xib awakeFromNib的警告问题

在Xcode 8之前我们使用Xib初始化- (void)awakeFromNib {}都是这么写也没什么问题,但是在Xcode 8会有如下警告:

如果不喜欢这个警告的话,应该明确的加上[super awakeFromNib];我们来看看官方说明:

You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

十一、Xcode 8编译过慢的问题

很多人都反映Xcode 8没有之前编译快了,甚至有些人慢的辣眼睛。但是我的没有感觉很慢,跟之前差不多,我觉得跟电脑应该有一些联系吧,有的开发者几个月不重启电脑,电脑里运行一堆线程,一堆没用的垃圾。下面是加速Xcode编译的方法,感兴趣的可以去看一下:

提高Xcode编译速度

十二、iOS 10 ImagePickerController.cameraViewTransform问题

很多人反映自定义相机出现了问题,cameraViewTransform不能用了,其实网上关于这个的资料不是很多,在这里提供参考办法如下:

通过监听AVCaptureSessionDidStartRunningNotification来解决

//#import //监听[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(cameraNotification:) name:AVCaptureSessionDidStartRunningNotification object:nil];//监听方法- (void)cameraNotification:(NSNotification*)notification {dispatch_async(dispatch_get_main_queue(), ^{// 这里实现imagePickerController.cameraViewTransform= CGAffineTransformMakeTranslation(50,50);

});

}

你可能感兴趣的:(iOS10资料和Xcode8的新特性和坑<二>)