记录我适配iOS26遇到的一些问题

这是适配iOS 26的笔记,并非介绍新功能和API。我只是把项目中遇到的适配问题记录起来。后续如果遇到新的问题会更新这个笔记。

1. 暂时关闭Liquid Glass 液态玻璃

在iOS26中,系统默认开启了Liquid Glass 液态玻璃效果。例如UINavigationBar和UITabBar等,并且是强制性的。但是在项目紧急上线,适配没有做好的情况可以暂时关闭这个效果。

当然苹果也给了最终限制,最多一年时间,下个主要版本就没这个属性了。不推荐长期使用,应尽快完成适配

只要在info.plist加上这一项即可:

swift 复制代码
<key>UIDesignRequiresCompatibility</key>

<true/>

2. 导航栏相关

2.1 导航栏按钮玻璃背景问题

在iOS 26中,导航栏按钮会出现大的圆角矩形玻璃背景,无法隐藏或关闭。这可能导致:

  • 按钮文字被遮挡

  • 图标偏移显示异常

  • 之前设置的偏移量不再适用

解决方案:

swift 复制代码
// 调整偏移量或更换居中的图标资源

// 之前可能设置了负值偏移让按钮靠前,现在需要重新调整

  


// 方法1: 重新设计图标,使用居中对齐的图标

// 方法2: 调整customView的布局约束
2.2 自定义View添加到NavigationBar的问题

将自定义view添加到navigationBar后,在iOS 26中会出现异常:

swift 复制代码
// 页面出现时添加

[self.navigationController.navigationBar addSubview:_naviView];

  


// 页面消失时移除

[_naviView removeFromSuperview];

现象: 开始正常显示,但从二级页面返回后view消失(图层中存在但不可见)

原因:

这时候由于Apple 对 UINavigationBar 做了多次底层改造:

| iOS版本 | 导航栏变化 | 影响 |

| ------- | ------------------------------------------------ | ------------------------------------ |

| iOS 15 | 引入 UINavigationBarAppearance | 改变背景和阴影绘制机制 |

| iOS 17+ | 导航栏层级变动,_UINavigationBarModernContentView 延迟加载 | 手动添加的子视图可能被系统布局或动画移除 |

| iOS 26 | NavigationBar使用新的 compositing layer 结构 | 非官方子视图在 appear/disappear 动画时被"吞掉"或遮盖 |

导致了在iOS26中,可能出现下面的问题:

会被系统的内部 layer 覆盖;

或者生命周期中 navigationBar 被重新创建;

导致 view 不再显示、被替换或无法响应。

这时候有三种解决方案:

swift 复制代码
// 解决方法1:一般不使用

// 把view添加到titleView上

// 优点:跟随导航栏生命周期自动管理,不会丢失或被覆盖。

// 缺点:只能放在标题区域,布局受限。

  


[self.navigationController.navigationItem.titleView addSubview:_naviView];

  


// 解决方法2:

// 放到 NavigationBar 的 superview 层(而非导航栏内部)

// 优点:可以放在任何位置,布局灵活。

// 缺点:需要手动管理生命周期,容易出错。

  


// ✅ 这样即使导航栏内部结构变动,你的 view 也不会丢。

// ⚠️ 记得在二级页面 viewWillAppear 时隐藏它。

[self.navigationController.view addSubview:_naviView];

  


// 临时解决方案:

// 延迟加载 view 到 navigationBar 上

// 确保在 navigationBar 完成布局后再添加 或者在viewDidAppear 中添加

dispatch_async(dispatch_get_main_queue(), ^{

[self.navigationController.view addSubview:_naviView];

});

  

3. TabBar相关

在最新版本中,TabBar的变动很大,

3.1 私有属性设置TabBar问题

❌ 不推荐的做法:

因为在iOS26中Apple 给 tabBar 属性加了 runtime 保护;这时候或者运行闪退或者是新增一个单独的tab

swift 复制代码
// 通过私有属性设置TabBar

[self setValue:self.customTabbar forKey:@"tabBar"];

问题: 在iOS 26中,Apple给tabBar属性加了runtime保护,会导致:

  • 运行时闪退

  • 新增一个单独的tab

  • 自定义TabBar失效

3.2 直接添加SubView的方式

如果是通过直接添加到tabbar上,这种显示基本没大问题,可能有中间大按钮的问题,且有玻璃效果。 但是可能造成点击失效的问题(被系统拦截)。 我项目中是使用的系统TabBar,没有自定义TabBar。 所以没有遇到这个问题。

swift 复制代码
// 直接添加到tabbar上

self.customTabbar.frame = self.tabBar.bounds;

[self.tabBar addSubview:self.customTabbar];

问题:

  • 显示基本正常,有玻璃效果

  • 中间大按钮可能有问题

  • 点击可能失效(被系统拦截)

3.3 自定义TabBar适配建议

如果你是自定义仿咸鱼的那种发布tabbar,可能出现只有四个tabarItem和中间一个发布图标的的情况。 这时候点击也会出问题。

这种情况就需要重新设计UI了,紧急修复,或者等三方库更新,或者再找找别的方法。

3.4 TabBar透明度问题

如果内容没有延伸到TabBar下方,检查是否设置了isTranslucent属性:

swift 复制代码
// iOS 26需要移除或条件编译

if #unavailable(iOS 26) {

tabBar.isTranslucent = false

}

我是没有遇到这个问题,因为我们应用首页是个collectionview,我还怕它延伸到tabbar下方,造成不好点击的问题。

4. 布局约束问题

在修改中我发现之前获取的kTopHeight(NaviBarHeight+StatusBarHeight) 会有问题。

原因如下:

  1. windowScene.statusBarManager.statusBarFrame 在某些时机是 0 或未更新(特别是多 Scene、导航过渡、或 navigationBar 异步布局时)。

  2. safeAreaInsets 由系统在 view 布局完成后才会精确计算,早用会得到旧值或 0。

  3. UINavigationBar 在 iOS 26 里可能异步构建(或使用新 compositing),导致你在 viewDidLoad/viewWillAppear 读取到不正确的高度。

  4. 如果你把子视图约束到 self.view.top 而不是 safeAreaLayoutGuide.top,内容会延伸到状态栏/导航栏下方(被遮盖)。

所以布局时使用 Safe Area(safeAreaLayoutGuide 或 view.safeAreaInsets)而不是 statusBarFrame。

swift 复制代码
//建议使用这个来获取高度

make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(0);

5. 图片导航栏按钮设置original仍显示蓝色

即使设置了UIImageRenderingModeAlwaysOriginal,在iOS 26中图片按钮仍显示为蓝色(系统tintColor)。

swift 复制代码
// ❌ 在iOS 26中无效

- (void)setNavigationBarBtn {

UIImage *addImg = [[UIImage imageNamed:@"规范_新增+"]

imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithImage:addImg

style:UIBarButtonItemStyleDone

target:self

action:@selector(addClient)];

self.navigationItem.rightBarButtonItems = @[add];

}

解决方案

方案1:设置tintColor为clearColor(推荐)

swift 复制代码
- (void)setNavigationBarBtn {

UIImage *addImg = [[UIImage imageNamed:@"规范_新增+"]

imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIImage *searchImg = [[UIImage imageNamed:@"放大镜"]

imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

  


UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithImage:addImg

style:UIBarButtonItemStylePlain

target:self

action:@selector(addClient)];

  


UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithImage:searchImg

style:UIBarButtonItemStylePlain

target:self

action:@selector(searchClient)];

  


// ✅ iOS 26修复方案

for (UIBarButtonItem *item in @[add, search]) {

item.tintColor = UIColor.clearColor; // 确保使用原图色

}

// ⚠️ 注意:iOS 26中左右顺序和之前版本相反

if (@available(iOS 26.0, *)) {

self.navigationItem.rightBarButtonItems = @[search, add];

} else {

self.navigationItem.rightBarButtonItems = @[add, search];

}

}

方案2:使用自定义UIButton

swift 复制代码
- (void)setNavigationBarBtn {

UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];

[addButton setImage:[UIImage imageNamed:@"规范_新增+"] forState:UIControlStateNormal];

addButton.frame = CGRectMake(0, 0, 30, 30);

[addButton addTarget:self action:@selector(addClient) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithCustomView:addButton];

self.navigationItem.rightBarButtonItems = @[add];

}
重要提醒

⚠️ iOS 26中导航栏按钮顺序变化:

在设置rightBarButtonItemsleftBarButtonItems时,iOS 26的显示顺序与之前版本相反,需要条件编译处理:

swift 复制代码
if (@available(iOS 26.0, *)) {

// iOS 26: 数组第一个元素显示在最右边

self.navigationItem.rightBarButtonItems = @[最右边的按钮, 中间按钮, 最左边的按钮];

} else {

// iOS 25及以下: 数组第一个元素显示在最左边

self.navigationItem.rightBarButtonItems = @[最左边的按钮, 中间按钮, 最右边的按钮];

}

补充 iPad相关

可以看这个大佬的iPad适配文章

相关推荐
QuantumLeap丶2 天前
《Flutter全栈开发实战指南:从零到高级》- 04 - Widget核心概念与生命周期
flutter·xcode
大熊猫侯佩3 天前
思过崖上学「 subprocess 」:令狐冲的 Swift 6.2 跨平台进程心法
spm·xcode·进程控制·platform·subprocess·output·swift 6.2
__基本操作__3 天前
西电25年A测 语音识别机械臂方案与教程
语音识别·机械臂·xcode·西电a测
疯笔码良5 天前
【Flutter】flutter安装并在Xcode上应用
flutter·macos·xcode
lichong9516 天前
【Xcode】Macos p12 证书过期时间查看
前端·ide·macos·证书·xcode·大前端·大前端++
_阿南_6 天前
flutter在Xcode26打包的iOS26上全屏支持右滑的问题
flutter·ios·xcode
驰羽9 天前
[GO]Go语言泛型详解
开发语言·golang·xcode
小瓶盖_tl11 天前
在Mac上安装CocoaPods问题处理
macos·xcode·cocoapods
zzywxc78715 天前
AI 在金融、医疗、教育、制造业等领域都有广泛且深入的应用,以下是这些领域的一些落地案例
人工智能·金融·自动化·prompt·ai编程·xcode