前言
iOS 26 的 UIKit 更新了不少东西,挑几个有意思的分享下。
UIBackgroundExtensionView
新增的一个 View,专门用来处理背景延伸到 unsafe area 的问题。
// 堆代码 duidaima.com
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.image = UIImage(resource: .iOS26Wallpaper)
let backgroundExtensionView = UIBackgroundExtensionView()
backgroundExtensionView.contentView = imageView
系统会自动处理延伸效果,用一些模糊、翻转地技巧让效果看起来自然。如果想自己控制布局,可以设置 automaticallyPlacesContentView = false

上图是加和不加 UIBackgroundExtensionView 的效果,可以明显看出对于安全区域的处理变化。
UIBarButtonItem 的新功能
导航栏按钮现在支持 Liquid Glass 背景了,相邻的按钮会自动共享背景。不想共享可以这样:
let plusBarButtonItem = UIBarButtonItem()
plusBarButtonItem.sharesBackground = false
还可以给按钮加 badge 了:
barButtonItem.badge = UIBarButtonItem.Badge(
value: "3",
font: .systemFont(ofSize: 12),
foregroundColor: .white,
backgroundColor: .red
)
注意只支持导航栏,工具栏不行。另外新增了 identifier 属性,用来优化自定义 customView 地转场动画。
UIViewController 观察者支持
新增了三个方法:
func updateProperties()
func setNeedsUpdateProperties()
func updatePropertiesIfNeeded()
还有个新属性 prefersInterfaceOrientationLocked,用来锁定屏幕方向,适合游戏类 App。
UIViewPropertyAnimator 改进
新增了 flushUpdates 属性,设置为 true 后动画 block 里就不用手动调用 layoutIfNeeded() 了:
let animator = UIViewPropertyAnimator(duration: 1, curve: .easeInOut)
animator.flushUpdates = true
animator.addAnimations {
heightConstraint.constant = 100
}
UIApplicationDelegate 方法废弃
苹果终于把一些老的 UIApplicationDelegate 方法标记废弃了:
废弃的方法
|
替代方法
|
applicationDidBecomeActive
|
sceneDidBecomeActive
|
applicationWillResignActive
|
sceneWillResignActive
|
application:openURL:
|
scene:openURLContexts:
|
其他功能
Writing Tools 新增了 presentationIntent 选项,返回语义化意图而不是具体样式。
UIView 新增了 cornerAdaptation 参数,用来处理异形屏地圆角布局。
iPadOS 新增了一些窗口系统地 API,支持检测窗口调整等。
整体来说这次更新还挺实用,特别是 Background Extension View 和 Bar Button Badge。
最后
你开始适配 iOS 26 了吗?有哪些功能你最喜欢?欢迎在评论区分享你的看法!
接下来我也会注重分享一些 iOS 26 适配技巧,敬请关注。