iOS15適配總結(持續更新)

前言:本文僅提供自己遇到的問題的一些解決方案,想了解更多api的變化可自行搜索。

1.UITableView 分組高度顯示異常處理方案

UITableView分組高度默認增加22個像素的高度,導致所有的UI顯示異常。

解決方案:

  • 全局設置(推薦)
    可以在 AppDelegate中直接全局設置生效,目前未發現不良影響
if (@available(iOS 15.0, *)) {
    [UITableView appearance].sectionHeaderTopPadding = 0;
}
  • 部分頁面設置
    針對單獨某個UITableView設置
if (@available(iOS 15.0, *)) {
    _tableView.sectionHeaderTopPadding = 0;
}
  • Runtime方式(僅提供方案,未驗證)
    創建UITableView的分類,在+ (void)load方法中交換initWithFrame:,并增加如下代碼
if (@available(iOS 15.0, *)) {
    _tableView.sectionHeaderTopPadding = 0;
}

2.導航欄顯示異常處理方案

iOS15之前的系統,用到了設置導航欄背景顏色的處理,或設置某種顏色或透明或顏色變化,但是在iOS15上全部失效,導致導航欄顯示異常。

解決方案:
創建UINavigationController分類,增加如下方法:

/// 設置導航欄顏色
-(void)setNavigationBackgroundColor:(UIColor *)color{
    NSDictionary *dic = @{NSForegroundColorAttributeName : [UIColor whiteColor],
                              NSFontAttributeName : [UIFont systemFontOfSize:18]};
    
    if (@available(iOS 15.0, *)) {
        // 滾動狀態
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        // 設置為不透明
        appearance.backgroundEffect = nil;
        appearance.backgroundImage = [UIImage imageWithColor:color];
        appearance.shadowColor = color;
        appearance.backgroundColor = color;

        // 靜止狀態
        UINavigationBarAppearance *appearance2 = [[UINavigationBarAppearance alloc] init];
        // 設置為不透明
        appearance2.backgroundEffect = nil;
        appearance2.backgroundImage = [UIImage imageWithColor:color];
        appearance2.shadowColor = color;
        appearance2.backgroundColor = color;

        self.navigationBar.scrollEdgeAppearance = appearance;
        self.navigationBar.standardAppearance = appearance2;
    }else{
        self.navigationBar.titleTextAttributes = dic;
        [self.navigationBar setShadowImage:[[UIImage alloc] init]];
        [self.navigationBar setBackgroundImage:[UIImage imageWithColor:color] forBarMetrics:UIBarMetricsDefault];
    }
}

將原來iOS15之前的如下代碼:

UIImage *image = [UIImage imageWithColor:color];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:image];

修改為:

[self.navigationController setNavigationBackgroundColor:color];

其中color為當前導航欄的顏色,可根據項目實際情況設置顏色

3.為ProMotion設備配置高刷權限

iPhone 13 Pro、iPhone 13 Pro Max 和 iPad ProMotion 顯示器能夠在以下各項之間動態切換:
刷新率高達 120Hz,低至 24Hz 或 10Hz 的較慢刷新率。

目前在iPhone 13 Pro 或 iPhone 13 Pro Max 上非官方APP默認不支持120Hz刷新率,其實只需要在Plist上配置以下權限,就可以使用上高刷,而Pad Pro 不需要這種特殊配置,默認支持高刷。

<key>CADisableMinimumFrameDurationOnPhone</key><true/>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容