iOS 15 UI適配

前言

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;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 簡(jiǎn)單寫(xiě)一些、還在摸索中... 1.升級(jí)iOS11后造成的變化 1. 1升級(jí)后,發(fā)現(xiàn)某個(gè)擁有tableView的界面...
    _VisitorsZsl閱讀 7,547評(píng)論 15 17
  • 前言 本著蘋果爸爸系統(tǒng)更新的一貫作風(fēng)(UI必亂),我開(kāi)始了iOS15的探索; 基于Xcode Version 13...
    e42f53e4b8ea閱讀 3,027評(píng)論 4 4
  • 1. 設(shè)置圖片圓角 2. UIAlertController 聲明并創(chuàng)建閉包,填充UIAlertAction的ha...
    俊瑤先森閱讀 3,576評(píng)論 0 8
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂(lè)有人憂愁,有人驚喜有人失落,有的覺(jué)得收獲滿滿有...
    陌忘宇閱讀 8,896評(píng)論 28 54
  • 信任包括信任自己和信任他人 很多時(shí)候,很多事情,失敗、遺憾、錯(cuò)過(guò),源于不自信,不信任他人 覺(jué)得自己做不成,別人做不...
    吳氵晃閱讀 6,391評(píng)論 4 8

友情鏈接更多精彩內(nèi)容