iOS 15 新特性適配


1、導航欄的性能做了優化,默認情況下,如果導航欄與視圖沒有折疊,導航欄的背景透明,如果系統檢測到有重疊的話,會變成毛玻璃的效果

if (@available(iOS 13.0, *)) { UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init]; [appearance setShadowImage:[[UIImage alloc] init]]; [appearance setBackgroundColor:TAD_THM.navigationBackgroundColor]; // 隱藏分割線 設置一個透明或者純色的圖片 設置nil 或者 [UIImage new]無效 [appearance setBackgroundImage:[UIImage zt_imageWithPureColor:[UIColor whiteColor]]]; [appearance setShadowImage:[UIImage zt_imageWithPureColor:[UIColor whiteColor]]]; [[UINavigationBar appearance] setScrollEdgeAppearance: appearance]; } 

顏色轉圖片

+ (UIImage *)zt_imageWithPureColor:(UIColor *)color { UIGraphicsBeginImageContextWithOptions(CGSizeMake(3, 3), NO, [UIScreen mainScreen].scale); UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 3, 3)]; [color setFill]; [p fill]; UIImage* img = UIGraphicsGetImageFromCurrentImageContext(); return img; } + (UIImage *)zt_imageWithPureColor:(UIColor *)color size:(CGSize )size{ UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale); UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, size.width, size.height)]; [color setFill]; [p fill]; UIImage* img = UIGraphicsGetImageFromCurrentImageContext(); return img; } 

2、UITableView新增了一條新屬性:sectionHeaderTopPadding, 默認會給每一個section header 增加一個高度,當我們使用 UITableViewStylePlain 初始化UITableView的時候,能發現sectionHeader增高了22px。解決辦法就是手動去除這個高度

if (@available(iOS 15.0, *)) { table.sectionHeaderTopPadding = 0; } 

3、UIImageWriteToSavedPhotosAlbum存儲圖片之后的回調不再返回圖片了,會返回nil,如果在回調方法里面操作image有可能會直接Crash,目前的解決辦法聲明一個全局image去記錄,后面再去操作

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





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM