iOS15適配

以iOS15和xcode13為環(huán)境基礎(chǔ),iOS15適配的一些更改和調(diào)整。

UINavigationBar

UITabBar

TableView

Image

ProMotion

CLLocationButton

UINavigationBar

用新xcode13編譯工程后,導(dǎo)航欄的問(wèn)題比較明顯,調(diào)試之后發(fā)現(xiàn)是UINavigationBar部分屬性的設(shè)置在iOS15上是無(wú)效的

OC:

// 修改NarBar背景if(@available(iOS15.0,*)){UINavigationBarAppearance*appearance=[[UINavigationBarAppearance alloc]init];// 背景色appearance.backgroundColor=[UIColor blueColor];// 去掉半透明效果appearance.backgroundEffect=nil;// 標(biāo)題字體顏色及大小appearance.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:18],};// 設(shè)置導(dǎo)航欄下邊界分割線透明appearance.shadowImage=[[UIImage alloc]init];// 去除導(dǎo)航欄陰影(如果不設(shè)置clear,導(dǎo)航欄底下會(huì)有一條陰影線)appearance.shadowColor=[UIColor clearColor];// standardAppearance:常規(guī)狀態(tài), 標(biāo)準(zhǔn)外觀,iOS15之后不設(shè)置的時(shí)候,導(dǎo)航欄背景透明self.navigationBar.standardAppearance=appearance;// scrollEdgeAppearance:被scrollview向下拉的狀態(tài), 滾動(dòng)時(shí)外觀,不設(shè)置的時(shí)候,使用標(biāo)準(zhǔn)外觀self.navigationBar.scrollEdgeAppearance=appearance;}else{navigationBar.setBackgroundImage(UIColor.clear.image,for:.default)// 導(dǎo)航欄背景,主題色是綠色navigationBar.barTintColor=UIColor.theme// 默認(rèn)不透明navigationBar.isTranslucent=false// 著色,讓返回按鈕圖片渲染為白色navigationBar.tintColor=UIColor.white// 導(dǎo)航欄文字navigationBar.titleTextAttributes=[NSAttributedString.Key.font:UIFont.systemFont(ofSize:18),NSAttributedString.Key.foregroundColor:UIColor.white]}

Swift

if#available(iOS15,*){let app=UINavigationBarAppearance.init()app.configureWithOpaqueBackground()// 重置背景和陰影顏色app.titleTextAttributes=[NSAttributedString.Key.font:UIFont.systemFont(ofSize:18),NSAttributedString.Key.foregroundColor:UIColor.white]app.backgroundColor=UIColor.theme// 設(shè)置導(dǎo)航欄背景色app.shadowImage=UIColor.clear.image// 設(shè)置導(dǎo)航欄下邊界分割線透明navigationBar.scrollEdgeAppearance=app// 帶scroll滑動(dòng)的頁(yè)面navigationBar.standardAppearance=app// 常規(guī)頁(yè)面}

UITabbar

tabbar的問(wèn)題和navigationBar的問(wèn)題屬于同一類,tabbar背景顏色設(shè)置失效,字體設(shè)置失效,陰影設(shè)置失效問(wèn)題。

OC

// 修改tabbar背景if(@available(iOS15.0,*)){UITabBarAppearance*appearance=[UITabBarAppearance new];//tabBar背景顏色appearance.backgroundColor=[UIColor whiteColor];// 去掉半透明效果appearance.backgroundEffect=nil;// tabBaritem title選中狀態(tài)顏色appearance.stackedLayoutAppearance.selected.titleTextAttributes=@{NSForegroundColorAttributeName:KColorFromRGB(0x53A2F8),NSFontAttributeName:[UIFont systemFontOfSize:12],};//tabBaritem title未選中狀態(tài)顏色appearance.stackedLayoutAppearance.normal.titleTextAttributes=@{NSForegroundColorAttributeName:KColorFromRGB(0x7E7E7E),NSFontAttributeName:[UIFont systemFontOfSize:12],};self.tabBar.scrollEdgeAppearance=appearance;self.tabBar.standardAppearance=appearance;}

Swift

if#available(iOS15,*){let bar=UITabBarAppearance.init()bar.backgroundColor=UIColor.white? ? bar.shadowImage=UIColor.init(0xEEEEEE).image? ? let selTitleAttr=[NSAttributedString.Key.font:itemFont,NSAttributedString.Key.foregroundColor:UIColor.theme]bar.stackedLayoutAppearance.selected.titleTextAttributes=selTitleAttr// 設(shè)置選中attributesself.tabBar.scrollEdgeAppearance=barself.tabBar.standardAppearance=bar}

UITableview

iOS15對(duì)于tableview,新增了sectionHeaderTopPadding作為列表每個(gè)部分標(biāo)題上方的填充,它的默認(rèn)值是UITableViewAutomaticDimension,所以我們要將他設(shè)置為0,否則當(dāng)我們的列表設(shè)置了section高度的列表會(huì)出現(xiàn)head高度增加的情況,適配方式:

// OCif(@available(iOS15.0,*)){self.tableView.sectionHeaderTopPadding=0;}// Swiftif#available(iOS15,*){tableView.sectionHeaderTopPadding=0}

Image

在iOS15中,UIImageWriteToSavedPhotosAlbum存儲(chǔ)圖片之后的回調(diào)不再返回圖片了,會(huì)返回nil,如果在回調(diào)方法里面操作image有可能會(huì)直接Crash,目前的解決辦法聲明一個(gè)全局image去記錄,后面再去操作:

self.image=savedImage;UIImageWriteToSavedPhotosAlbum(savedImage,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);-(void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{// self.image doing...}

新增了幾個(gè)調(diào)整尺寸的方法:

// preparingThumbnailUIImage(named:"sv.png")?.preparingThumbnail(of:CGSize(width:200,height:100))// prepareThumbnail,閉包中直接獲取調(diào)整后的UIImageUIImage(named:"sv.png")?.prepareThumbnail(of:CGSize(width:200,height:100)){imagein// 需要回到主線程更新UI}awaitUIImage(named:"sv.png")?.byPreparingThumbnail(ofSize:CGSize(width:100,height:100))

系統(tǒng)圖片支持多個(gè)層,支持多種渲染模式:

// preparingThumbnailUIImage(named:"sv.png")?.preparingThumbnail(of:CGSize(width:200,height:100))// prepareThumbnail,閉包中直接獲取調(diào)整后的UIImageUIImage(named:"sv.png")?.prepareThumbnail(of:CGSize(width:200,height:100)){imagein// 需要回到主線程更新UI}awaitUIImage(named:"sv.png")?.byPreparingThumbnail(ofSize:CGSize(width:100,height:100))

ProMotion設(shè)備配置高刷權(quán)限

iPhone 13 Pro、iPhone 13 Pro Max 和 iPad ProMotion 顯示器能夠在以下各項(xiàng)之間動(dòng)態(tài)切換:

刷新率高達(dá) 120Hz,低至 24Hz 或 10Hz 的較慢刷新率。

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

<key>CADisableMinimumFrameDurationOnPhone</key><true/>

CLLocationButton

該內(nèi)容內(nèi)置于CoreLocationUI模塊,但如果需要獲取定位的詳細(xì)信息仍然需要借助于CoreLocation。

let locationButton=CLLocationButton()// 文字locationButton.label=.currentLocationlocationButton.fontSize=20// 圖標(biāo)locationButton.icon=.arrowFilled// 圓角locationButton.cornerRadius=10// tintlocationButton.tintColor=UIColor.systemPink// 背景色locationButton.backgroundColor=UIColor.systemGreen// 點(diǎn)擊事件,應(yīng)該在在其中發(fā)起定位請(qǐng)求locationButton.addTarget(self,action:#selector(getCurrentLocation),for:.touchUpInside)

僅做記錄用,轉(zhuǎn)自:http://www.itdecent.cn/p/47df8b769f7f

?著作權(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)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • UINavigationBar 記得一定要 iOS15 和已以前的版本都好好測(cè)一下,適配的時(shí)候一定要保留之前的導(dǎo)航...
    鐵汁紅豆閱讀 1,105評(píng)論 0 2
  • 本文主要分享一下 iOS15 上適配方案,僅做開發(fā)記錄使用,開發(fā)過(guò)程中通過(guò)使用陸續(xù)增加。 iOS15 的適配,很重...
    smile麗語(yǔ)閱讀 5,396評(píng)論 11 24
  • UINavigationBar 用新 xcode13 編譯工程后,導(dǎo)航欄的問(wèn)題比較明顯,調(diào)試之后發(fā)現(xiàn)是 UINav...
    林希品閱讀 3,914評(píng)論 0 10
  • 1、tabbar相關(guān) UITabBarAppearance *appearance = [[UITabBarApp...
    吳斌閱讀 410評(píng)論 0 0
  • 本文作為自己準(zhǔn)備適配iOS15所用,在開始適配之前,先去學(xué)習(xí)各位同學(xué)的文章,記錄在此備用。 1、導(dǎo)航欄UINavi...
    iOS_zy閱讀 14,736評(píng)論 5 61

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