一.Dark Mode
首先说万金油适配方法,如果希望在iOS依旧保持原来的样子,就在plist文件增加key-value,如图
1.)全局适配
不设置背景颜色的视图,背景颜色会根据系统设置的模式改变
iOS13中uiviewcontroller和uiview新增了overrideUserInterfaceStyle属性,通过设置这个属性可以改变vc或view本身及其子视图的模式(light和dark和unspecified)
也就是说App既可以接受手机系统设置,也可以不接受,由开发者主动设置
如果给window设置,会影响window上的所有vc和view,以及模态处理的视图比如uialertcontroller,不过不建议这么做,最好按照上面说的那样设置plist文件.
模拟器可以动态的修改模式,不过是在xcode上设置,debug状态下才生效。
2.)监听状态
//在vc中重写方法
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{
[super traitCollectionDidChange:previousTraitCollection];
if (@available(iOS 13.0, *)) {
self.view.backgroundColor = self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ? [UIColor blackColor] : [UIColor whiteColor];
NSLog(@"previousTraitCollection=%ld,overrideUserInterfaceStyle=%ld,self.traitCollection.userInterfaceStyle=%ld",previousTraitCollection.userInterfaceStyle,self.overrideUserInterfaceStyle,self.traitCollection.userInterfaceStyle);
}
}
切换dark mode后,这里的输出结果是 previousTraitCollection=1,overrideUserInterfaceStyle=0,self.traitCollection.userInterfaceStyle=2,
1.方法中的参数previousTraitCollection是模式改变之前的状态
2.vc的属性overrideUserInterfaceStyle是限定这个vc或view及其子视图的模式,赋值成除UIUserInterfaceStyleUnspecified之外的时候,即使系统修改模式,这个vc重写的traitCollectionDidChange方法也不会被调用
3.获取当前的模式需要使用vc的traitCollection属性中的userInterfaceStyle
3.)UIColor
新增了动态颜色。并且提供了五个大种类,很多种预设颜色,也可以用code创建动态颜色,新增了三个方法。
4.)图片
可以在assets.xcassets设置不同模式下的图片
二.statusBar
现在是三种模式,default是根据系统设置改变
UIStatusBarStyleDefault;
UIStatusBarStyleLightContent;
UIStatusBarStyleDarkContent.
三.模态弹出presentViewcontroller
UIModalPresentationStyle增加了一个UIModalPresentationAutomatic,并且在iOS13中是默认这个值,而之前默认的是UIModalPresentationFullScreen
UIModalPresentationAutomatic自带手势下拉dismiss
1)需要注意的是vc高度也发生变化了,并且viewdidload中和实际的高度不一样
2)生命周期
UIModalPresentationAutomatic和UIModalPresentationFullScreen不同,当A弹出B时,如果是UIModalPresentationFullScreen,A是会调用disappear相关生命周期方法的,B dismiss时,A也会调用appear相关方法,而UIModalPresentationAutomatic不会.
四.KVC不允许使用私有方法
比如UITextField:
[textF setValue:DescrbeColor forKeyPath:@"_placeholderLabel.textColor"];
会crash,
可以替换成
textF.attributedPlaceholder = [[NSMutableAttributedString alloc]initWithString:@" " attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:DescrbeColor}];
五.新建工程
iOS13工程结构发生了变化,有两个代理
SceneDegelate.h
window不再由APPDelegate管理,这是为ipad os做的准备,普通项目直接在APPDelegate.h中添加一个window就可以了
六.其他新特性
1)iOS 13 中 tableView 和 collectionView 增加双指滑动编辑的功能
2)新增了文本的手势,在原生控件中默认是生效的,可以禁止,选中文字后,可以操作复制和剪切 ,可以在光标的位置操作粘贴,还可以撤销,反撤销,呼出菜单
重写editingInteractionConfiguration方法可以选择禁止这些手势
复制:三指捏合
剪切:两次三指捏合
粘贴:三指松开
撤销:三指向左划动(或三指双击)
重做:三指向右划动
快捷菜单:三指单击
3)iOS 13新增了UIMenu控件