1. UITabBarButtonItem液态玻璃效果
兼容处理:
第一种方式(不推荐):把所有的UITabBarButtonItem关闭液态玻璃效果:
objectivec
if (@available(iOS 26.0, *)) {
self.navigationItem.rightBarButtonItem.hidesSharedBackground = YES;
self.navigationItem.leftBarButtonItem.hidesSharedBackground = YES;
} else {
// Fallback on earlier versions
}
第二种方式:所有导航栏按钮全部采用UITabBarButtonItem,支持液态玻璃效果。
2. 采用UILayoutFittingExpandedSize设置自定义的navigationItem.titleView的内容尺寸,在iOS26上高度偏大,高度变为屏幕的高度,预期是高度应该为导航栏的高度;
原因:在iOS26之前UILayoutFittingExpandedSize最大尺寸限制在导航栏范围内,而在iOS26则允许充斥整个屏幕:
objectivec
- (CGSize)intrinsicContentSize { return UILayoutFittingExpandedSize; }
兼容处理:
修改intrinsicContentSize,指定titleView的尺寸大小为导航栏大小:
objectivec
#define SCREEN_WIDTH ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.width)
- (CGSize)intrinsicContentSize { return CGSizeMake(SCREEN_WIDTH, 44); }
3、UITabBarController调用self.setValue(yourTabBar, forKey: "tabBar")自定义tabBar失效
原因:iOS 26 之后对 UITabBarController 的 KVC 注入限制,导致无效,但不会crash
兼容处理:改为使用系统的UITabBarItem组件,能够支持新系统的液态玻璃效果