本文主要是介绍iOS15出现的问题及其适配,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、iOS15中对导航栏的性能做了优化,默认如果导航栏与视图没有折叠,导航栏的背景是透明的,如果系统检测到有重叠的话,会变成毛玻璃的效果。
if (@available(iOS 15.0, *)) {UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];[appearance setShadowImage:[[UIImage alloc] init]];[appearance setBackgroundColor:TAD_THM.navigationBackgroundColor];[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;
}
UINavigationBar默认是透明的,当滑动时会逐渐变为模糊效果,我们可以改变scrollEdgeAppearance属性直接变为模糊效果。
if (@available(iOS 15.0, *)){UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];navBar.scrollEdgeAppearance = appearance;
}
2、iOS15中UITableView新增了一个属性sectionHeaderTopPadding, 默认会给每一个section header 增加一个高度,当我们使用 UITableViewStylePlain 初始化UITableView的时候,能发现sectionHeader增高了22px,头部会出现留白的情况。
解决办法:
if (@available(iOS 15.0, *)) {table.sectionHeaderTopPadding = 0;
}
全局适配设置
if (@available(iOS 15.0, *)) {[UITableView appearance].sectionHeaderTopPadding = CGFLOAT_MIN;
}
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{}
这篇关于iOS15出现的问题及其适配的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!