iOS15适配

422 阅读1分钟

1、导航栏 

在iOS15中UINavigationBar默认会有一个透明状态,如果项目中大多数页面都是有背景的导航栏,那么在进入页面和侧滑返回的时候就会出现特别“生硬”的效果。

if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        [appearance configureWithOpaqueBackground];
        appearance.titleTextAttributes = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:17], NSForegroundColorAttributeName : [UIColor colorWithHexValue:0x0f0f0f]}; // 字体颜色是根据项目来说的
        appearance.shadowColor = [UIColor clearColor]; // 导航栏底下线条设置成透明颜色
        [[UINavigationBar appearance] setStandardAppearance:appearance];
        [[UINavigationBar appearance] setScrollEdgeAppearance:appearance];
    }

2、UITableview

iOS15的tableview新增了一个sectionHeaderTopPadding属性,每个section标题上方的填充。它的默认值是UITableViewAutomaticDimension,我们可以全局的把它设置为0,去解决这个问题。

if (@available(iOS 15.0, *)) {
        [UITableView appearance].sectionHeaderTopPadding = 0.1;
    }

3、UIimage

在iOS15中 UIImageWriteToSavedPhotosAlbum的回调方法不再给image参数回调了。

UIImageWriteToSavedPhotosAlbum(image, self, @selector(UIImageWriteToSavedPhotosAlbum_completedWithImage:error:context:), NULL);
//...

// @available(iOS 15.0, *) image == nil
- (void)UIImageWriteToSavedPhotosAlbum_completedWithImage:(UIImage *)image error:(NSError *)error context:(void *)context {
}