以iOS15和xcode13為環(huán)境基礎,iOS15適配的一些更改和調整。
UINavigationBar
UITabBar
TableView
Image
ProMotion
CLLocationButton
UINavigationBar
用新xcode13編譯工程后正驻,導航欄的問題比較明顯肘交,調試之后發(fā)現(xiàn)是UINavigationBar部分屬性的設置在iOS15上是無效的
OC:
// 修改NarBar背景if(@available(iOS15.0,*)){UINavigationBarAppearance*appearance=[[UINavigationBarAppearance alloc]init];// 背景色appearance.backgroundColor=[UIColor blueColor];// 去掉半透明效果appearance.backgroundEffect=nil;// 標題字體顏色及大小appearance.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:18],};// 設置導航欄下邊界分割線透明appearance.shadowImage=[[UIImage alloc]init];// 去除導航欄陰影(如果不設置clear炬搭,導航欄底下會有一條陰影線)appearance.shadowColor=[UIColor clearColor];// standardAppearance:常規(guī)狀態(tài), 標準外觀漏益,iOS15之后不設置的時候,導航欄背景透明self.navigationBar.standardAppearance=appearance;// scrollEdgeAppearance:被scrollview向下拉的狀態(tài), 滾動時外觀谋竖,不設置的時候红柱,使用標準外觀self.navigationBar.scrollEdgeAppearance=appearance;}else{navigationBar.setBackgroundImage(UIColor.clear.image,for:.default)// 導航欄背景,主題色是綠色navigationBar.barTintColor=UIColor.theme// 默認不透明navigationBar.isTranslucent=false// 著色蓖乘,讓返回按鈕圖片渲染為白色navigationBar.tintColor=UIColor.white// 導航欄文字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// 設置導航欄背景色app.shadowImage=UIColor.clear.image// 設置導航欄下邊界分割線透明navigationBar.scrollEdgeAppearance=app// 帶scroll滑動的頁面navigationBar.standardAppearance=app// 常規(guī)頁面}
UITabbar
tabbar的問題和navigationBar的問題屬于同一類锤悄,tabbar背景顏色設置失效,字體設置失效嘉抒,陰影設置失效問題零聚。
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// 設置選中attributesself.tabBar.scrollEdgeAppearance=barself.tabBar.standardAppearance=bar}
UITableview
iOS15對于tableview,新增了sectionHeaderTopPadding作為列表每個部分標題上方的填充些侍,它的默認值是UITableViewAutomaticDimension隶症,所以我們要將他設置為0,否則當我們的列表設置了section高度的列表會出現(xiàn)head高度增加的情況岗宣,適配方式:
// OCif(@available(iOS15.0,*)){self.tableView.sectionHeaderTopPadding=0;}// Swiftif#available(iOS15,*){tableView.sectionHeaderTopPadding=0}
Image
在iOS15中蚂会,UIImageWriteToSavedPhotosAlbum存儲圖片之后的回調不再返回圖片了,會返回nil耗式,如果在回調方法里面操作image有可能會直接Crash胁住,目前的解決辦法聲明一個全局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...}
新增了幾個調整尺寸的方法:
// preparingThumbnailUIImage(named:"sv.png")?.preparingThumbnail(of:CGSize(width:200,height:100))// prepareThumbnail刊咳,閉包中直接獲取調整后的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)圖片支持多個層彪见,支持多種渲染模式:
// preparingThumbnailUIImage(named:"sv.png")?.preparingThumbnail(of:CGSize(width:200,height:100))// prepareThumbnail,閉包中直接獲取調整后的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設備配置高刷權限
iPhone 13 Pro娱挨、iPhone 13 Pro Max 和 iPad ProMotion 顯示器能夠在以下各項之間動態(tài)切換:
刷新率高達 120Hz余指,低至 24Hz 或 10Hz 的較慢刷新率。
目前在iPhone 13 Pro 或 iPhone 13 Pro Max 上非官方APP默認不支持120Hz刷新率跷坝,其實只需要在Plist上配置以下權限酵镜,就可以使用上高刷碉碉,而Pad Pro 不需要這種特殊配置,默認支持高刷笋婿。
<key>CADisableMinimumFrameDurationOnPhone</key><true/>
CLLocationButton
該內容內置于CoreLocationUI模塊誉裆,但如果需要獲取定位的詳細信息仍然需要借助于CoreLocation。
let locationButton=CLLocationButton()// 文字locationButton.label=.currentLocationlocationButton.fontSize=20// 圖標locationButton.icon=.arrowFilled// 圓角locationButton.cornerRadius=10// tintlocationButton.tintColor=UIColor.systemPink// 背景色locationButton.backgroundColor=UIColor.systemGreen// 點擊事件缸濒,應該在在其中發(fā)起定位請求locationButton.addTarget(self,action:#selector(getCurrentLocation),for:.touchUpInside)
僅做記錄用,轉自:http://www.reibang.com/p/47df8b769f7f