这是适配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) 会有问题。
原因如下:
-
windowScene.statusBarManager.statusBarFrame 在某些时机是 0 或未更新(特别是多 Scene、导航过渡、或 navigationBar 异步布局时)。
-
safeAreaInsets 由系统在 view 布局完成后才会精确计算,早用会得到旧值或 0。
-
UINavigationBar 在 iOS 26 里可能异步构建(或使用新 compositing),导致你在 viewDidLoad/viewWillAppear 读取到不正确的高度。
-
如果你把子视图约束到 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中导航栏按钮顺序变化:
在设置rightBarButtonItems
或leftBarButtonItems
时,iOS 26的显示顺序与之前版本相反,需要条件编译处理:
swift
if (@available(iOS 26.0, *)) {
// iOS 26: 数组第一个元素显示在最右边
self.navigationItem.rightBarButtonItems = @[最右边的按钮, 中间按钮, 最左边的按钮];
} else {
// iOS 25及以下: 数组第一个元素显示在最左边
self.navigationItem.rightBarButtonItems = @[最左边的按钮, 中间按钮, 最右边的按钮];
}
补充 iPad相关
可以看这个大佬的iPad适配文章