- iOS10中字体跟随系统设置变化大小
/*
*在iOS10中,当用户将手机的字体大小进行了设置调整之后,那么app中设置相关代码字体也会跟着一起变化,支持常见一
*些字体UI控件 比如UILabel、UIButton等
**/
[super viewDidLoad];
//设置字体的改变大小
self.labels.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
//允许改变
/*
苹果官方明确须和 preferredFontForTextStyle或者preferredFontForTextStyle:(NSString *)style compatibleWithTraitCollection 进行结合使用。注意:这里不支持模拟器操作
**/
self.labels.adjustsFontForContentSizeCategory = YES;
- UIApplication对象的openUrl被废弃:iOS10之前直接使用[[UIApplication sharedApplication] openURL 方法就可以使用应用程序去打开一个网页或者进行跳转,但是在iOS 10之后,有一个成功的回调block 可以进行监视,进而去处理返回的结果;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""] options:nil completionHandler:^(BOOL success) {
}];
- 语音识别:speech具有以下特点:
可以实现连续的语音识别
可以对语 音文件或者语音流进行识别
最佳化自由格式的听写(可理解为多语言支持)和搜索式的字符串
核心代码:(需要引入“ Speech/Speech.h”库)
//1.创建本地化标识符
NSLocale *locale =[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
//2.创建一个语音识别对象
SFSpeechRecognizer *recognizer =[[SFSpeechRecognizer alloc] initWithLocale:locale];
//3.将bundle 中的资源文件加载出来返回一个url
NSURL *url =[[NSBundle mainBundle] URLForResource:@"xxx.mp3" withExtension:nil];
//4.将资源包中获取的url传递给request对象
SFSpeechURLRecognitionRequest *res =[[SFSpeechURLRecognitionRequest alloc] initWithURL:url];
//5.发送一个请求
[recognizer recognitionTaskWithRequest:res resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"语音识别解析失败,%@",error);
} else {
//解析正确
NSLog(@"%@",result.bestTranscription.formattedString);
}
}];
- UIViewPropertyAnimator属性动画器:在iOS10,苹果推出了一个全新的API UIViewPropertyAnimator,可供我们处理动画操作;
UIViewPropertyAnimator 是 iOS 10 中新增的一个执行 View 动画的类,具有以下特点:
1、可中断性;
2、可擦除;
3、可反转性;
4、丰富的动画时间控制功能。
核心代码:
@interface ViewController ()
@property(nonatomic,strong) UIView *myView;
@property(nonatomic,strong) UIViewPropertyAnimator *myViewProperty;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.创建一个View对象
UIView *Views =[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
Views.backgroundColor =[UIColor yellowColor];
[self.view addSubview:Views];
//2.创建一个外部的变量进行引用
self.myView = Views;
//3.创建一个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.myViewProperty = viewPro;
}
//结束
- (IBAction)stop:(id)sender {
// YES 和NO 适用于设置当前这个属性动画器是否可以继续使用
[self.myViewProperty stopAnimation:YES];
}
//继续
- (IBAction)continued:(id)sender {
//UITimingCurveProvider
/**
@property(nullable, nonatomic, readonly) UICubicTimingParameters *cubicTimingParameters;
@property(nullable, nonatomic, readonly) UISpringTimingParameters *springTimingParameters;
**/
//设置弹簧效果 DampingRatio取值范围是 0-1
//这个取值决定弹簧抖动效果的大小 ,越往0靠近那么就越明显
UISpringTimingParameters *sp =[[UISpringTimingParameters alloc] initWithDampingRatio:0.01];
//设置一个动画的效果
// UICubicTimingParameters *cub =[[UICubicTimingParameters alloc] initWithAnimationCurve:UIViewAnimationCurveEaseInOut];
//durationFactor 给一个默认值 比如1.0就可以
[self.myViewProperty continueAnimationWithTimingParameters:sp durationFactor:1.0];
}
//暂停
- (IBAction)puase:(id)sender {
[self.myViewProperty pauseAnimation];
}
//开始
- (IBAction)start:(id)sender {
[self.myViewProperty startAnimation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- UIColor 新增方法:在iOS10中,苹果官方新增了colorWithDisplayP3Red方法
+ (
UIColor
*)colorWithDisplayP3Red:(
CGFloat
)displayP3Red green:(
CGFloat
)green blue:(
CGFloat
)blue alpha:(
CGFloat
)alpha
NS_AVAILABLE_IOS
(
10
_0);
iOS10 对隐私权限的管理
比如访问的摄像头、麦克风等硬件,都需要提前请求应用权限、允许后才可以使用,或者现在要提前声明,虽然以往要求不严格。在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添加一个描述。
Xcode7 和Xcode 8项目中的xib兼容问题
在Xcode8上打开项目要小心,尤其是对于xib过程,在变动后可不要随意点保存,否则当你回头用Xcode7打开时时发现报错了,Xcode8保存的xib在xcode7上是识别不了的!CoreData提升了并发访问性能
APPlePlay(苹果支付):可用于 SFSafariViewController,没有UI的extensions,在 iMessage 应用中也支持 ApplePay;
刷新控件(UIRefresh Control):系统自带的刷新控件支持所有的 UIScrollView 以及其子类,比如说 UICollectionView,UITableView。
GCD多线程支持创建私有队列
User Notifications和CallKit以及第三方键盘的改进等。