UINavigationBar

在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];
}

UITabbar

用新Xcode13编译iOS15项目后,tabbar的问题和navigationBar的问题属于类类似,运行起来后发现,tabbar背景颜色设置失效,字体颜色也失效,并且阴影设置也失效。查看TabBar的相关API:从 iOS 15 开始, UITabBar 在控制器中关联滚动视图底部时使用UITabBarAppearance.scrollEdgeAppearance配置相关属性-背景、字体等,所以做如下适配:

// 修改tabbar背景
if (@available(iOS 15.0, *)) { 
        UITabBarAppearance *appearance = [UITabBarAppearance new];
        //tabBar背景颜色
        appearance.backgroundColor = [UIColor whiteColor];
       // 去掉半透明效果
        appearance.backgroundEffect = nil;
       // tabBaritem title选中状态颜色
       appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{
            NSForegroundColorAttributeName:[UIColor blueColor],
            NSFontAttributeName:[UIFont systemFontOfSize:12],
        };
        //tabBaritem title未选中状态颜色
        appearance.stackedLayoutAppearance.normal.titleTextAttributes =  @{
            NSForegroundColorAttributeName:[UIColor grayColor],
            NSFontAttributeName:[UIFont systemFontOfSize:12],
        };
        self.tabBar.scrollEdgeAppearance = appearance;
        self.tabBar.standardAppearance = appearance;
}

UITableview

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

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

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 {
}

升级iOS15系统后,即使是低版本打的包也会出现截图被自动放大的问题,很多商家对此问题进行了反馈,发现iOS15可能对PHImageContentMode做了调整所以做一下适配:把PHImageContentModeAspectFill 改为 PHImageContentModeAspectFit

UImage新增一下方法

//异步同步准备此图像以在指定屏幕上显示
/// Synchronously prepares this image for displaying on the specified screen.
- (nullable UIImage *)imageByPreparingForDisplay API_AVAILABLE(ios(15.0),tvos(15.0),watchos(8.0));

/// Asynchronously prepares this image for displaying on the specified screen.
- (void)prepareForDisplayWithCompletionHandler:(void (^)(UIImage *_Nullable))completionHandler NS_SWIFT_ASYNC_NAME(byPreparingForDisplay()) API_AVAILABLE(ios(15.0),tvos(15.0),watchos(8.0));

//调整尺寸
- (nullable UIImage *)imageByPreparingThumbnailOfSize:(CGSize)size API_AVAILABLE(ios(15.0),tvos(15.0),watchos(8.0));

- (void)prepareThumbnailOfSize:(CGSize)size completionHandler:(void (^)(UIImage *_Nullable))completionHandler NS_SWIFT_ASYNC_NAME(byPreparingThumbnail(ofSize:)) API_AVAILABLE(ios(15.0),tvos(15.0),watchos(8.0));

iOS15 flutter字体自动加粗问题

分析原因是如果在写fontStyle的时候,默认字体宽度是FontWeight.normal(w400),iOS15之后iOS展示出来的FontWeight.normal粗细几乎变成了iOS15之前的w300;

那么如何解决这个问题呢,如果是基于JDFlutter的话,无法通过设置主题来解决,可以通过每个页面的根组件外面包一层DefaultTextStyle临时解决或者直接升级sdk来解决,我们是从 1.17.5到1.22.5解决的这个问题的;如果不是的话,可以通过以下方案来解决:

一个方案是整体升级flutter sdk,另一个方案是不升级通过设置默认全局字体的fontFamily属性、一个是全局设置theme主题字体大小

@override
  Widget build(BuildContext context) {
   const FontWeight weightIos = FontWeight.w300;
   //ios 字体样式
    var themeDataIos = ThemeData(
        textTheme: const TextTheme(
          headline1: TextStyle(fontWeight: weightIos),
          headline2: TextStyle(fontWeight: weightIos),
          headline3: TextStyle(fontWeight: weightIos),
          headline4: TextStyle(fontWeight: weightIos),
          headline5: TextStyle(fontWeight: weightIos),
          headline6: TextStyle(fontWeight: weightIos),
          subtitle1: TextStyle(fontWeight: weightIos),
          subtitle2: TextStyle(fontWeight: weightIos),
          bodyText1: TextStyle(fontWeight: weightIos),
          bodyText2: TextStyle(fontWeight: weightIos),
        )
      );
   //默认字体样式
   var themeDataDefault = ThemeData(
       textTheme: const TextTheme(
         headline1: TextStyle(fontWeight: FontWeight.normal),
         headline2: TextStyle(fontWeight: FontWeight.normal),
         headline3: TextStyle(fontWeight: FontWeight.normal),
         headline4: TextStyle(fontWeight: FontWeight.normal),
         headline5: TextStyle(fontWeight: FontWeight.normal),
         headline6: TextStyle(fontWeight: FontWeight.normal),
         subtitle1: TextStyle(fontWeight: FontWeight.normal),
         subtitle2: TextStyle(fontWeight: FontWeight.normal),
         bodyText1: TextStyle(fontWeight: FontWeight.normal),
         bodyText2: TextStyle(fontWeight: FontWeight.normal),
       )
   );
    return MaterialApp(
      theme: Platform.isIOS ? themeDataIos : themeDataDefault,
      home: JmHome(),
    );