轉(zhuǎn)發(fā)iOS 13[beta] presentViewController 默認(rèn)樣式的變化 + 問(wèn)題解決方案
本文對(duì)應(yīng)系統(tǒng)版本為 iOS 13
問(wèn)題分析
在iOS 13之前,我們模態(tài)展示的視圖默認(rèn)是全屏的。但是更新到iOS13之后,默認(rèn)的樣式變成iPhone上Safari展示的分頁(yè)樣式。
在使用 presentViewController 來(lái)跳轉(zhuǎn)視圖時(shí)系統(tǒng)提供了兩個(gè)參數(shù)來(lái)簡(jiǎn)化跳轉(zhuǎn)的設(shè)置,modalTransitionStyle 和 modalPresentationStyle。前者為轉(zhuǎn)場(chǎng)過(guò)渡的類型,后者為展示的樣式,系統(tǒng)為兩者都提供了多種可選樣式。
在iOS13前,展示的方式 modalPresentationStyle 的值默認(rèn)為0,即 .fullScreen。
而此時(shí),在 iOS13 中變?yōu)榱?2。
在 iOS13 中 modalPresentationStyle 的類型新增了以下類型:
UIModalPresentationAutomatic = -2
modalPresentationStyle的所有展示類型:

官方文檔中能看到該參數(shù)的如下描述:
Use this value when you want to use the system's recommended presentation style. For most view controllers, UIKit maps this style to the UIModalPresentationPageSheet style, but some system view controllers may map to a different style.
如果你想使用系統(tǒng)推薦的演示樣式就使用此值,對(duì)于絕大部分視圖控制器,UIKit將此值映射到UIModalPresentationPageSheet,但也有一些系統(tǒng)視圖控制器會(huì)映射到不同樣式
除了 “UISearchController” 和 “UIAlertController” 因?yàn)樽陨順I(yè)務(wù)的特殊性不同外,其余的視圖控制器均為 UIModalPresentationPageSheet 的展示樣式。
另外,展現(xiàn)隱私政策的視圖SFSafariViewController展示樣式默認(rèn)全屏,不用更改。
解決方案
在需要全屏展示的VC中添加代碼:
- (instancetype)init
{
self = [super init];
if (self) {
self.modalPresentationStyle = UIModalPresentationFullScreen;
}
return self;
}
有問(wèn)題歡迎評(píng)論。
其他對(duì)于iOS13適配做的工作
APP 內(nèi)全局關(guān)閉暗黑模式
解決方案
plist 里面添加如下鍵值:
<key>UIUserInterfaceStyle</key>
<string>UIUserInterfaceStyleLight</string>
UIUserInterfaceStyle為
- UIUserInterfaceStyleLight
- UIUserInterfaceStyleDark
UITextField通過(guò)KVC方式修改空白提示語(yǔ)顏色 崩潰
[UITextField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor”];
問(wèn)題分析
私有API被封禁(KVC限制),禁止訪問(wèn)
解決方案
使用attributedPlaceholder
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:placeStr attributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}];
inputTextField.attributedPlaceholder = attString;
LaunchImage即將被廢棄
從 iOS 8 的時(shí)候,蘋果就引入了 LaunchScreen,我們可以設(shè)置 LaunchScreen來(lái)作為啟動(dòng)頁(yè)。
當(dāng)然,現(xiàn)在你還可以使用LaunchImage來(lái)設(shè)置啟動(dòng)圖。
不過(guò)使用LaunchImage的話,要求我們必須提供各種屏幕尺寸的啟動(dòng)圖,來(lái)適配各種設(shè)備,隨著蘋果設(shè)備尺寸越來(lái)越多,這種方式顯然不夠 Flexible。
而使用 LaunchScreen的話,情況會(huì)變的很簡(jiǎn)單, LaunchScreen是支持AutoLayout+SizeClass的,所以適配各種屏幕都不在話下。
??從2020年4月開始,所有使? iOS13 SDK的 App將必須提供 LaunchScreen,LaunchImage即將退出歷史舞臺(tái)??梢允褂肔aunchScreen.storyboard來(lái)進(jìn)行解決。
tabBarItem 選中狀態(tài)的顏色無(wú)效,顯示默認(rèn)的藍(lán)色
解決方案
以前只設(shè)置選中狀態(tài)的顏色是可以的
[vc.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: MENU_ITEM_SELECTED_COLOR, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected
現(xiàn)在可以這樣設(shè)置
if (@available(iOS 13.0, *)) {
self.tabBar.tintColor = MENU_ITEM_SELECTED_COLOR;
} else {
[vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: MENU_ITEM_SELECTED_COLOR} forState:UIControlStateSelected];
}