iOS 15 新特性适配
原创
©著作权归作者所有:来自51CTO博客作者mb62cf8bca18558的原创作品,请联系作者获取转载授权,否则将追究法律责任
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...
}