iOS开发-iOS15适配踩坑

1.导航栏显示

iOS15中,苹果对导航栏的性能做了优化,默认情况下,如果导航栏与视图没有折叠,导航栏的背景透明,如果系统检测到有重叠的话,会变成毛玻璃的效果

这个效果会影响到一种情况,就是当前页面导航栏隐藏,然后下一个页面导航栏显示的时候,进行push或者从下一个页面pop时,导航栏处动画会有异样

我的解决办法

 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 Section的header增加默认间距
解决办法

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

你可能感兴趣的:(iOS开发-iOS15适配踩坑)