前言
iOS 15在2021 WWDC會(huì)后發(fā)布,就勇猛的把水果全家桶都升級(jí)了最新系統(tǒng)。兩個(gè)iOS 15 beta版本過(guò)后,系統(tǒng)穩(wěn)定性整體還不錯(cuò)。也隨之發(fā)現(xiàn)了幾個(gè)iOS適配上的bug,在此整理記錄下來(lái)。后續(xù)有發(fā)現(xiàn)再繼續(xù)補(bǔ)充。
Xcode Version 13.0 beta
iOS 15 Developer Beta2
1. UINavigationBar
- 在iOS 15中,UINavigationBar默認(rèn)為透明。在滑動(dòng)時(shí)會(huì)有模糊效果。如果想要一直就是模糊效果,可以通過(guò)改變scrollEdgeAppearance屬性來(lái)實(shí)現(xiàn)。
解決辦法:
UINavigationBarAppearance *barApp = [[UINavigationBarAppearance alloc] init];
barApp.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
self.navigationBar.scrollEdgeAppearance = barApp;
- NavigationBar顏色設(shè)置無(wú)效
self.navigationController.navigationBar.barTintColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];
往常我們用以上代碼來(lái)設(shè)置導(dǎo)航欄和狀態(tài)欄背景色,此代碼在iOS 15的無(wú)效。
apple developer forums
As of iOS 15, UINavigationBar, UIToolbar, and UITabBar will use their scrollEdgeAppearance when your view controller's associated scroll view is at the appropriate edge (or always if you don't have a UIScrollView in your hierarchy, more on that below).
You must adopt the UIBarAppearance APIs (available since iOS 13, specializations for each bar type) to customize this behavior. UIToolbar and UITabBar add scrollEdgeAppearance properties for this purpose in iOS 15.
從 iOS 15 開(kāi)始,UINavigationBar、UIToolbar 和 UITabBar 將在你的VC關(guān)聯(lián)滾動(dòng)視圖位于適當(dāng)?shù)倪吘墪r(shí)使用 scrollEdgeAppearance(或者如果您的試圖層級(jí)結(jié)構(gòu)中沒(méi)有 UIScrollView,更多內(nèi)容見(jiàn)下文)。
您必須使用 UIBarAppearance API 來(lái)自定義。UIToolbar 和 UITabBar 為此在 iOS 15 中添加了 scrollEdgeAppearance 屬性。
/// Describes the appearance attributes for the tabBar to use when an observable scroll view is scrolled to the bottom. If not set, standardAppearance will be used instead.
@property (nonatomic, readwrite, copy, nullable) UITabBarAppearance *scrollEdgeAppearance UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(15.0));
/// Describes the appearance attributes for the toolbar to use at standard height when an observable scroll view is scrolled to the bottom. If not set, standardAppearance will be used instead.
@property (nonatomic, readwrite, copy, nullable) UIToolbarAppearance *scrollEdgeAppearance UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(15.0));
解決辦法:
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];
barApp.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];
self.navigationController.navigationBar.scrollEdgeAppearance = barApp;
self.navigationController.navigationBar.standardAppearance = barApp;
}
2. iOS 15 UITableView sectionHeader下移22像素
iOS 15中 UITableView 新增了一個(gè)屬性:sectionHeaderTopPadding。此屬性會(huì)給每一個(gè) section header 增加一個(gè)默認(rèn)高度,當(dāng)我們使用 UITableViewStylePlain 初始化UITableView 的時(shí)候,系統(tǒng)默認(rèn)給 section header 增高了22像素。
/// Padding above each section header. The default value is
UITableViewAutomaticDimension.
@property (nonatomic) CGFloat sectionHeaderTopPadding API_AVAILABLE(ios(15.0), tvos(15.0), watchos(8.0));
解決辦法:
if (@available(iOS 15.0, *)) {
tableView.sectionHeaderTopPadding = 0;
}