一.Dark Mode
首先說(shuō)萬(wàn)金油適配方法,如果希望在iOS依舊保持原來(lái)的樣子,就在plist文件增加key-value,如圖

1.全局適配
不設(shè)置背景顏色的視圖,背景顏色會(huì)根據(jù)系統(tǒng)設(shè)置的模式改變
iOS13中uiviewcontroller和uiview新增了overrideUserInterfaceStyle屬性,通過(guò)設(shè)置這個(gè)屬性可以改變vc或view本身及其子視圖的模式(light和dark和unspecified)
也就是說(shuō)App既可以接受手機(jī)系統(tǒng)設(shè)置,也可以不接受,由開(kāi)發(fā)者主動(dòng)設(shè)置
如果給window設(shè)置,會(huì)影響window上的所有vc和view,以及模態(tài)處理的視圖比如uialertcontroller,不過(guò)不建議這么做,最好按照上面說(shuō)的那樣設(shè)置plist文件.
模擬器可以動(dòng)態(tài)的修改模式,不過(guò)是在xcode上設(shè)置,debug狀態(tài)下才生效,如圖

2.監(jiān)聽(tīng)狀態(tài)
//在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后,這里的輸出結(jié)果是 previousTraitCollection=1,overrideUserInterfaceStyle=0,self.traitCollection.userInterfaceStyle=2,
1.方法中的參數(shù)previousTraitCollection是模式改變之前的狀態(tài)
2.vc的屬性overrideUserInterfaceStyle是限定這個(gè)vc或view及其子視圖的模式,賦值成除UIUserInterfaceStyleUnspecified之外的時(shí)候,即使系統(tǒng)修改模式,這個(gè)vc重寫的traitCollectionDidChange方法也不會(huì)被調(diào)用
3.獲取當(dāng)前的模式需要使用vc的traitCollection屬性中的userInterfaceStyle
3.UIColor
新增了動(dòng)態(tài)顏色
3.1.在assets.xcassets中創(chuàng)建


并且提供了五個(gè)大種類,很多種預(yù)設(shè)顏色,System colors, Foreground colors ,Background colors ,Fill colors ,Other colors

3.2.可以用code創(chuàng)建動(dòng)態(tài)顏色
新增了三個(gè)方法

UIView *v = [[UIView alloc]initWithFrame:CGRectMake(200, 100, 100, 100)];
if (@available(iOS 13.0, *)) {
v.backgroundColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
return traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ? [UIColor whiteColor] : [UIColor blackColor];
}];
} else {
v.backgroundColor = [UIColor yellowColor];
}
[self.view addSubview:v];
if (@available(iOS 11.0, *)) {
UIColor *c = [UIColor colorNamed:@"999999_c"];
}
999999_c就是assets.xcassets中的命名,注意colorNamed:只在iOS11及以上可以使用此api,colorWithDynamicProvider:只在iOS 13及以上可以使用
4.圖片
可以在assets.xcassets設(shè)置不同模式下的圖片

二.statusBar
現(xiàn)在是三種模式,default是根據(jù)系統(tǒng)設(shè)置改變

適配上來(lái)說(shuō),之前設(shè)置了default的 ,在iOS13上也還是default,不過(guò)不再是固定的黑色,之前設(shè)置default的如果希望和原來(lái)一樣,需要改成UIStatusBarStyleDarkContent
三.模態(tài)彈出presentViewcontroller
先說(shuō)適配,可以在公共父類的init中設(shè)置modalPresentationStyle 為 UIModalPresentationFullScreen
1.iOS13 presentViewcontroller樣式發(fā)生變化
UIModalPresentationStyle增加了一個(gè)UIModalPresentationAutomatic,并且在iOS13中是默認(rèn)這個(gè)值,而之前默認(rèn)的是UIModalPresentationFullScreen
UIModalPresentationAutomatic自帶手勢(shì)下拉dismiss
需要注意的是vc高度也發(fā)生變化了,并且viewdidload中和實(shí)際的高度不一樣



2.生命周期
UIModalPresentationAutomatic和UIModalPresentationFullScreen不同,當(dāng)A彈出B時(shí),如果是UIModalPresentationFullScreen,A是會(huì)調(diào)用disappear相關(guān)生命周期方法的,B dismiss時(shí),A也會(huì)調(diào)用appear相關(guān)方法,而UIModalPresentationAutomatic不會(huì).
四.KVC不允許使用私有方法
比如UITextField
[textF setValue:DescrbeColor forKeyPath:@"_placeholderLabel.textColor"];
會(huì)crash
可以替換成
textF.attributedPlaceholder = [[NSMutableAttributedString alloc]initWithString:@" " attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:DescrbeColor}];
只需要設(shè)置以此,用空格占位,之后設(shè)置textF.placeholder就行
五.新建工程
iOS13工程結(jié)構(gòu)發(fā)生了變化,有兩個(gè)代理

window不再由APPDelegate管理,這是為iapd os做的準(zhǔn)備,普通項(xiàng)目直接在APPDelegate.h中添加一個(gè)window就可以了
六.其他新特性
- iOS 13 中 tableView 和 collectionView 增加雙指滑動(dòng)編輯的功能
2.新增了文本的手勢(shì),在原生控件中默認(rèn)是生效的,可以禁止,選中文字后,可以操作復(fù)制和剪切 ,可以在光標(biāo)的位置操作粘貼,還可以撤銷,反撤銷,呼出菜單
重寫editingInteractionConfiguration方法可以選擇禁止這些手勢(shì)
復(fù)制:三指捏合
剪切:兩次三指捏合
粘貼:三指松開(kāi)
撤銷:三指向左劃動(dòng)(或三指雙擊)
重做:三指向右劃動(dòng)
快捷菜單:三指單擊
3.iOS 13新增了UIMenu控件
