iOS15 新特性兼容适配

1.用xcode13编译工程后,导航栏的问题比较明显,原因是UINavigationBar部分属性的设置在iOS15上是无效的。

  if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *bar = [UINavigationBarAppearance new];
        [bar setBackgroundColor:RPBackGroundColor];
        [bar setBackgroundImage:[UIImage new]];
        bar.shadowColor = [UIColor clearColor];
        self.navigationController.navigationBar.standardAppearance = bar;
        self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
    }else{
        //导航底部的分割线置为空白
        [self.navigationController.navigationBar setShadowImage:[UIImage new]];
        [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    }

2. 设置导航栏颜色  setBarTintColor 方法失效
 

- (void)navgationSetBarTintColor:(UIColor *)color{
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *bar = [UINavigationBarAppearance new];
        [bar setBackgroundColor:color];
        [bar setBackgroundImage:[UIImage new]];
        bar.shadowColor = [UIColor clearColor];
        self.navigationController.navigationBar.standardAppearance = bar;
        self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
    }else{
        [self.navigationController.navigationBar setBarTintColor:color];
    }
}

3.tabbar的问题和navigationBar的问题属于同一类,tabbar背景颜色设置失效,字体设置失效,阴影设置失效问题

if (@available(iOS 15.0, *)) {
        UITabBarAppearance *appearance = [UITabBarAppearance new];
        appearance.backgroundColor = [UIColor whiteColor];
        // 设置未被选中的颜色
        appearance.stackedLayoutAppearance.normal.titleTextAttributes = attrs;
        // 设置被选中时的颜色
        appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttrs;
        [appearance setBackgroundColor:[UIColor whiteColor]];
        [appearance setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];
        [appearance setShadowImage:[UIImage imageWithColor:hexColor(@"#F4F4FF")]];
        self.tabBar.standardAppearance = appearance;
        self.tabBar.scrollEdgeAppearance = self.tabBar.standardAppearance;
    }else{
        UITabBarItem *item = [UITabBarItem appearance];
        [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
        [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    }


+ (UIImage *)imageWithColor:(UIColor *)color {
    CGSize size = CGSizeMake(1, 1);
    if (!color || size.width <= 0 || size.height <= 0) return nil;
    CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

3. UITableView

iOS15对于tableview,新增了sectionHeaderTopPadding作为列表每个部分标题上方的填充,默认增加22px,它的默认值是UITableViewAutomaticDimension,所以我们要将他设置为0,否则当我们的列表设置了section高度的列表会出现head高度增加的情况,适配方式:

 if (@available(iOS 15.0, *)) {
         self.sectionHeaderTopPadding = 0;
     }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 将iframe嵌入网页的兼容性问题主要涉及以下两个方面: 1. iOS 的 Safari 浏览器对于iframe中嵌入的内容的加载和显示可能存在一些限制。首先,由于安全性考虑,iOS的Safari浏览器在加载iframe中的网页时会采取一些措施,比如禁止执行动态脚本、阻止下载非安全资源等,这可能导致一些功能无法正常使用或显示异常。其次,iOS Safari 对于iframe中的内容的尺寸自适应支持可能有限,如果父页面和嵌入的页面在尺寸上存在不匹配,可能会导致显示效果不理想。 2. iOS设备上的触摸操作也可能影响到iframe的使用体验。由于iOS设备主要采用触控屏幕,与桌面设备的鼠标操作存在一些差异,因此在iframe中的交互元素(比如按钮、链接等)可能需要专门适配和处理触摸事件,以实现良好的用户体验。 为了解决iOS iframe兼容性问题,可以考虑以下几点: 1. 确保iframe中嵌入的内容是符合iOS Safari浏览器要求的,避免使用动态脚本、非安全资源等。 2. 在设计父页面和嵌入页面时,尽量保持尺寸的一致性,以避免显示问题。可以通过CSS样式或JavaScript来调整和适配尺寸。 3. 针对iOS设备的触摸操作特性,对iframe中的交互元素进行专门的适配和处理,确保用户可以正常操作和使用。 综上所述,iOS Safari浏览器中iframe的兼容性问题主要包括内容加载和显示限制以及触摸操作的适配。通过遵循浏览器的规范并针对iOS设备进行适配,可以解决这些问题,提升用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值