View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 转写文稿
  • 代码
  • 升级改造你的 UIKit App

    探索 UIKit 的最新更新。了解如何更新 iPhone App 的布局,以便在调整大小时能够呈现出色效果,让你的 App 无论是通过 iPhone 镜像功能使用还是显示在 iPad 上都相宜。探索适用于标签栏和导航栏的全新 API,并了解如何针对 Apple 智能的新功能准备好的 App。我们还将介绍一种充分利用所选编码智能体的技巧,帮助你实现代码库现代化。

    章节

    • 0:00 - Introduction
    • 0:34 - App adaptivity
    • 2:10 - Legacy API: App lifecycle
    • 2:51 - Legacy API: Main screen
    • 5:46 - Full-screen mode for games
    • 6:17 - Legacy API: User interface idiom
    • 6:50 - Legacy API: Interface orientation
    • 7:55 - UIView Body protocols for motion & location
    • 8:19 - Test your resizable iPhone app
    • 9:18 - Tab bars and sidebars
    • 10:52 - Navigation bars
    • 12:37 - Menus
    • 13:01 - Integrate with Apple Intelligence
    • 14:07 - Agentic coding
    • 15:32 - Next steps

    资源

    • TN3208: Preparing your app’s launch screen to meet App Store requirements
    • TN3210: Optimizing your app for iPhone Mirroring
    • Make your UIKit app more flexible
    • Adapting your app when traits change
    • Transitioning to the UIKit scene-based life cycle
    • Automatic trait tracking
    • Human Interface Guidelines: Menus
      • 高清视频
      • 标清视频

    相关视频

    WWDC26

    • 充分利用 Device Hub
    • 探索适用于 Siri 和 Apple 智能的 App Intents 高级功能

    WWDC25

    • 让你的 UIKit App 更加灵活

    WWDC24

    • 提升 iPadOS 中的标签页和边栏使用体验
  • 搜索此视频…

    你好 我是Michael Ochs UI框架团队的工程经理

    今天我将向你介绍 如何现代化你的UIKit应用 在这个视频中 我将介绍 应用适应性需求的一些重大变化 以及iPhone应用如何 实现完全可调整大小 接下来 我将介绍标签栏 导航栏和菜单中的新API 然后 我将讲解 如何支持Apple Intelligence 以及你需要了解的一些变化

    最后 我将介绍一项新技能 它可以帮助智能体处理 大部分现代化工作 自动完成

    让我们从应用适应性开始 你的应用已经可以在 多种不同的环境中运行 屏幕尺寸各不相同 应用可以并排运行 与其他应用甚至与自身同时运行 在iPad上 用户希望应用能够 无缝调整大小并移至外部显示器 在iPhone上 用户期望应用能在 竖屏和横屏模式下正常使用 他们还期望能将iPhone 镜像投射到Mac上 在iOS和macOS 27中 这一体验已得到改善 在这些环境中运行的应用 现在会面临 平台原生应用所需支持的 许多动态变化

    当用户在Mac上使用iPhone镜像时 可以完全调整iPhone窗口的大小 让你的应用能够 调整大小并适应环境 同样 在iPad上运行的 纯iPhone应用将完全可调整大小 就像任何其他iPad应用一样 因此 你的应用必须能够 动态调整 以适应运行时任何可用的 场景大小 如果你的应用是通用二进制文件 你已经有了一个好的开始 但还需要做更多工作 使你的应用完全适应并动态 适应其运行的环境 我将介绍最重要的步骤 以及你可能遇到的常见问题 在提升应用适应性时 验证你的应用 是否已停止使用应用生命周期 转而采用场景生命周期 这是任何自适应应用的基础 确保你的应用没有使用 主屏幕引用 以及如何处理用户界面惯用法 和界面方向检查

    第一步是从应用生命周期 迁移到场景生命周期 大多数应用 已经使用场景生命周期 它是自适应应用的基础 也是许多其他任务的基础 这些将在本视频中展示 使用最新SDK构建时 现在需要UIScene生命周期 没有它 你的应用将无法启动 验证你的应用 是否正在使用UISceneDelegate 这是场景生命周期的基础 如果你还没有迁移到场景生命周期 请观看视频 来自WWDC25的 "Make your UIKit app more flexible" 以及阅读"Transitioning to the UIKit scene-based lifecycle" 文档中的相关内容 接下来 当你的iPhone应用 在Mac上进行镜像时 或者当用户将应用 移至iPad的外部显示器时 与你的场景关联的 屏幕会发生变化 这意味着代码中对 主屏幕的任何引用都会提供 与应用运行环境 不符的错误信息 重要的是 不要在应用中 引用主屏幕 应从窗口的windowScene 动态获取屏幕信息 当视图或视图控制器 在当前上下文中不可用时 将屏幕引用传递给 任何需要它的方法 比获取正确屏幕更好的做法是 完全移除屏幕引用 有许多其他API 更适合自适应应用 我将带你了解 两种常见模式 访问屏幕缩放比例 应替换为 使用特征集合的displayScale 视图和视图控制器 会自动更新其特征集合 并提供合理的降级处理 即使它们不在 可见层级中 许多常见的覆盖点 也会被追踪 这意味着你不需要 显式监控变化 系统会追踪哪些 特征集合属性正在被使用 在常见的布局和绘制方法中 如layoutSubviews、updateProperties drawRect等 如果检测到被追踪特征的变化 系统将确保这些方法 再次被调用 从而让UI 自动进行相应更新 请查阅文档中的 "Automatic trait tracking"了解更多 在无法使用自动特征追踪的地方 可使用registerForTraitChanges 来监听变化 此方法允许你设置一个闭包 当特定特征 在接收视图中发生变化时调用 使用它来使缓存失效 或更新与该视图相关的其他数据 请查阅 "Adapting your app when traits change" 文档以了解更多 屏幕的另一个常见用途是 检查其边界以获取 应用可用空间的大小 然而 在自适应环境中 场景可用的空间 并非总是整个屏幕 因此 如果应用中仍有 对屏幕边界的引用 现在是时候移除它们了 窗口场景的有效几何形状 提供了可用空间 的相关信息 如果需要监控有效几何形状的变化 请实现 在场景代理中实现 windowScene:didUpdateEffectiveGeometry: 在视图和视图控制器中 不要引用场景边界 而应使用视图控制器视图 或父视图的可用大小 来确定可用空间的大小 这使你的UI减少对 呈现方式的依赖 当视图控制器出现在 其他上下文中时能更好地适应 例如在分屏视图控制器内部 对于游戏而言 调整大小可能比较困难 因此 从iOS 27开始 iPhone上可调整大小的 环境中支持UIRequiresFullscreen 其行为也已更新 不再让应用完全 退出调整大小功能 而是启用离散调整大小 并遵循 你支持的界面方向 在离散调整大小模式下 每次用户更改场景大小时 系统会将场景过渡到 新的屏幕配置 以匹配该大小 使游戏始终在可用空间中 以最高质量渲染 如果你的应用正在使用 用户界面惯用法特征 请注意 此特征对任何 布局决策不再有意义 你的应用应以有意义的方式 使用额外的空间 无论是在手机还是 平板用户界面惯用法下运行 当你的iPhone应用在iPad上运行 或在Mac上的iPhone镜像中运行时 它将完全可调整大小 但仍将在手机 用户界面惯用法下运行 停止在代码中 使用用户界面惯用法进行布局决策 改用尺寸类别来处理尺寸约束 例如折叠菜单 以及根据可用空间 更新应用布局 如果需要更精细的控制 请使用周围视图的大小 如我之前所提到的 界面方向同样不再适用于 布局决策 在iOS 27中 应用支持的界面方向 是提供给系统的一个偏好设置 当应用在可调整大小的环境中运行时 将被忽略 布局计算中不应考虑 界面方向 在Mac上的iPhone镜像中 你的应用将始终运行 在竖屏界面方向下 无论应用场景的 长宽比如何 应用中对界面方向的检查 也应更新为使用尺寸类别 这个概念转变 是在iOS 8中引入的 在WWDC2014上 Bruce Nilo说道 "设备旋转只是 一次有动画的边界变化" 随着设备尺寸的多样化 iPad上的可调整窗口 以及Mac上可调整大小的iPhone应用 如今这一见解 比以往任何时候都更为重要 说到界面方向 在iOS 27中 UIView也符合新的 来自CoreMotion和CoreLocation的 Body协议 这使得配置运动和位置管理器 变得更加容易 将它们连接到 可视化运动数据的视图 例如指南针或地图视图 这确保数据始终处于 正确的坐标空间 无论界面方向如何 以上就是主要的适应性变化 现在来看看如何在 应用中测试这些变化 Xcode 27带来了新的方式 来迭代应用在 不同屏幕尺寸下的行为 无需在多个独立的 模拟器或设备上安装应用

    在新的Device Hub应用 以及Xcode Previews中 点击"进入调整大小模式"图标 然后 拖动设备边缘 自由调整大小 这让你能够更快地 迭代变更 对结果满意后 务必使用真实设备测试iPhone镜像 以及iPad

    要了解更多关于 Device Hub应用及其工具的信息 观看"Get the most out of Device Hub" 这就是适应性 在向你展示一项新的智能编码技能 它可以帮助你完成 使应用完全自适应所需的工作之前 还有两个话题要介绍 首先是 栏和菜单 在iPad上 标签栏可以展开 为完整的侧边栏形式 以在当前环境支持侧边栏时 展示应用层级的更多部分 在当前环境 支持侧边栏时 在iPhone上 底部标签栏 默认在所有尺寸下显示

    iOS 27新增功能 iPhone应用 也可以通过设置选择侧边栏 将标签栏控制器的 sidebar.preferredPlacement设为.sidebar 请注意 与iPad不同 这是应用的选择 如果应用选择了侧边栏形式 则无法在UI中切换 侧边栏和 标签栏布局之间的切换 系统决定是否有足够的空间 来显示侧边栏 例如当水平尺寸类别 为regular时

    要确定标签栏的侧边栏形式 是否可以显示 使用侧边栏的isAvailable属性 如果侧边栏当前不可用 在应用其他部分的嵌套标签中展示相关UI 在应用的其他部分展示 要了解更多关于管理标签组的信息 观看来自WWDC25的 "Make your UIKit app more flexible" 以及了解更多关于标签栏 及其与侧边栏集成的信息 观看来自WWDC24的 "Elevate your tab and sidebar experience in iPadOS"

    UITabBarController还允许你 自定义突出标签 突出标签始终可见 即使在滚动时 标签栏收起也不例外 在iOS 27中 你可以选择 让任何标签成为突出标签 通过设置prominentTabIdentifier 好了 这就是标签栏 现在来讲导航栏

    导航栏可以随着 用户滚动而交互式滑出 这为你的应用内容 提供了更多屏幕空间 默认情况下 导航栏会在 系统定义的某些条件下最小化

    你可以强制控制这一行为 任选一种方式 通过设置 barMinimizationBehavior属性 在导航项上设置 .always或.never 如果你自行处理 安全区域回避 将barMinimizationSafeAreaAdjustment设为 .never 使栏最小化不会自动更新 内边距

    滚动交互期间的另一个变化是 更新后的外观 用于滚动边缘效果 因此 你应检查你的设计 特别是在你之前覆盖了 操作系统默认值的地方 特别是.automatic样式 不再在 现有的soft和hard样式之间切换 而是提供自己的视觉效果 以增强清晰度 如果你之前将样式从 .automatic覆盖 该决定应重新评估 尤其是设置为.soft时 因为它不再与 默认系统外观相匹配

    借助Liquid Glass的精致外观 你在菜单元素上设置的图像 在某些上下文中可能默认不显示 例如在iPadOS和macOS 的菜单栏中 如果你仍需要图像可见 设置preferredImageVisibility属性 以覆盖默认系统行为 请查阅更新后的 人机界面指南 了解何时在菜单元素中 显示图像 以上就是栏和菜单的内容 现在 如何在应用中 支持Apple Intelligence

    iOS 27中的菜单 新增了"询问Siri"按钮 让用户可以直接在应用中 开始与Siri的对话 这是一个强大的入口点 让用户能够与 他们关心的内容进行交互

    当有与Siri相关的内容时 菜单将自动显示此项目 为了提供更多与你的应用 相关的特定信息 使用新的View Annotations API 使用它你可以用AppEntities 注解特定视图 请查阅 "Explore advanced App Intents features for Siri and Apple Intelligence" 了解更多

    如果你的应用支持拖放 Siri可以从 应用的拖动处理程序加载资源 当从上下文菜单调用Apple Intelligence时 系统将调用 可用的拖动代理方法 来加载内容 避免在sessionWillBegin中 执行动画或呈现模态UI 拖动会话可以在 没有用户手势的情况下启动 如果你的应用有一个有状态的UI 在用户启动拖动时显示 请将该代码放入sessionDidMove中

    如果我概述的适应性变化 听起来工作量很大 别担心 来聊聊大家都在关注的话题 智能编码!

    Xcode 27的新功能 是一项应用现代化技能 它深入理解 我概述的适应性任务 结合你项目的上下文 它可以自动完成 许多这些变更 使用Xcode的智能功能 让智能体使你的应用更具适应性 它将自动将主屏幕调用 转换为traitCollection 或场景边界检查 必要时添加失效逻辑 它还将把界面方向检查 替换为尺寸类别检查 它甚至可以将你的应用 转换为使用场景生命周期 对于更复杂的任务 它会提出澄清性问题 对于过大无法在 单次会话中处理的任务 它会添加注释 帮助你追踪 剩余的工作

    要在其他工具中使用技能 你可以导出Xcode使用的技能 使用 "xcrun agent skills export" 这将创建Markdown文件 然后你可以在工作流中导入 这样的技能是 使应用做好准备 适应可调整大小环境的强大方式

    就这些了! 这些是现代化应用 最重要的事项 使用iOS 27 SDK构建应用 并在新的Device Hub应用中 试用可调整大小的模拟器 并在macOS 27上的 iPhone镜像中测试应用 找出应用中需要 更灵活的区域 如果你喜欢智能编码 不妨尝试这项新技能 看看它能自动完成 多少工作 感谢你的参与 我迫不及待地想看看 你调整大小后的应用

    • 3:24 - Use local screen references

      // Use local screen references
      // Access the correct screen through a windowScene
      let screen = window?.windowScene?.screen
      
      // Pass in local screen references
      func generateThumbnail(_ image: UIImage, screen: UIScreen) -> UIImage {
          // existing code, replacing main screen with local screen reference
          // ...
      }
    • 3:49 - Replace screen scale with displayScale

      // Replace the screen's scale with trait collection's displayScale
      override func layoutSubviews() {
          super.layoutSubviews()
      
          // layoutSubviews will be called again automatically when displayScale changes
          let displayScale = traitCollection.displayScale
          // ...
      }
    • 4:36 - Register for trait changes

      // Manually register for trait changes
      let displayScaleTrait: [UITrait] = [UITraitDisplayScale.self]
      registerForTraitChanges(displayScaleTrait) {
          (view: GalleryView, previousTraitCollection: UITraitCollection) in
          view.cache.invalidate()
      }
    • 5:19 - Monitor effective geometry changes

      // UIWindowSceneDelegate
      func windowScene(
          _ windowScene: UIWindowScene,
          didUpdateEffectiveGeometry previousEffectiveGeometry: UIWindowScene.Geometry
      ) {
          let geometry = windowScene.effectiveGeometry
          let availableSpace = geometry.coordinateSpace.bounds
          // ...
      }
    • 5:35 - Check available space using view bounds

      // Checking available space
      override func viewDidLayoutSubviews() {
          super.viewDidLayoutSubviews()
      
          let availableSpace = view.bounds.size
          // ...
      }
    • 8:12 - Configure motion and location body

      // Configure motion and heading bodies
      override func viewDidLoad() {
          super.viewDidLoad()
      
          motionManager.deviceMotionBody = view
          locationManager.headingBody = view
      }
    • 9:51 - Opt into sidebar layout

      tabBarController.sidebar.preferredPlacement = .sidebar
    • 10:22 - Check sidebar availability

      tabBarController.sidebar.isAvailable
    • 10:53 - Set prominent tab identifier

      // Set the prominent tab
      let tabs = [
          // ...
      ]
      let tabBarController = UITabBarController(tabs: tabs)
      tabBarController.prominentTabIdentifier = "cart"
    • 11:30 - Customize bar minimization behavior

      // Customize bar minimization behavior
      override init(
          nibName nibNameOrNil: String?,
          bundle nibBundleOrNil: Bundle?
      ) {
          super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
      
          navigationItem.barMinimizationBehavior = .always
          navigationItem.barMinimizationSafeAreaAdjustment = .never
      }
    • 15:05 - Export Xcode skills for use in other tools

      xcrun agent skills export
    • 0:00 - Introduction
    • A modern UIKit app dynamically adjusts to the environment it runs in. iOS 27 introduces new requirements and APIs to help you get there. Discover new APIs in tab bars, navigation bars, and menus; Apple Intelligence support; and a new skill that helps an agent handle much of this modernization work automatically.

    • 0:34 - App adaptivity
    • iPhone apps are now fully resizable in iPhone Mirroring on Mac and when running on iPad. Your app needs to dynamically adjust to any available scene size at runtime. The four areas to audit are scene lifecycle adoption, main screen references, user interface idiom checks, and interface orientation checks.

    • 2:10 - Legacy API: App lifecycle
    • UIScene lifecycle is now required when building with the latest SDKs; apps without it will no longer launch. If you haven't migrated from app lifecycle yet, start here.

    • 2:51 - Legacy API: Main screen
    • UIScreen.main always refers to the device's main screen, but in resizable environments your scene may be running on a different screen entirely. Replace it with screen references from the window scene, trait collections for scale, and effective geometry for available space.

    • 5:46 - Full-screen mode for games
    • UIRequiresFullscreen is now honored on iPhone in resizable environments, enabling discrete resizing that respects your supported interface orientations so games always render at full quality.

    • 6:17 - Legacy API: User interface idiom
    • The user interface idiom trait is no longer meaningful for layout. An iPhone app running on iPad stays in the phone idiom but is fully resizable. Use size classes instead.

    • 6:50 - Legacy API: Interface orientation
    • Supported interface orientations are treated as a preference only and are ignored in resizable environments, including iPhone Mirroring which always reports portrait. Replace orientation checks with size classes.

    • 7:55 - UIView Body protocols for motion & location
    • UIView now conforms to the new Body protocols from CoreMotion and CoreLocation in iOS 27, making it straightforward to keep motion and location data in the correct coordinate space regardless of interface orientation.

    • 8:19 - Test your resizable iPhone app
    • Xcode 27's Device Hub app and Xcode Previews let you freely drag the edges of the simulator to test any screen size without needing multiple devices. Test with real devices for iPhone Mirroring and iPad.

    • 9:18 - Tab bars and sidebars
    • iPhone apps can now opt into a sidebar layout by setting tabBarController.sidebar.preferredPlacement to .sidebar, with the system deciding when there's enough space to show it. Check tabBarController.sidebar.isAvailable to determine if the system can show the sidebar, and use tabBarController.prominentTabIdentifier to pin any tab so it stays visible even when the tab bar collapses during scroll.

    • 10:52 - Navigation bars
    • Navigation bars can now slide away during scroll to give people more room. The system determines when this happens by default; override it with barMinimizationBehavior. The .automatic scroll edge effect style has new visuals; apps that previously overrode it to .soft should re-evaluate their design.

    • 12:37 - Menus
    • Menu element images may no longer appear by default in some contexts like menu bars on iPadOS and macOS. Use preferredImageVisibility to override this behavior where needed.

    • 13:01 - Integrate with Apple Intelligence
    • Menus automatically display an Ask Siri button when there's content relevant for Siri. If your app supports drag and drop, Siri can load resources from your drag handlers. Drag sessions can be initiated without a user gesture, so avoid triggering animations or presenting modal UI from sessionWillBegin.

    • 14:07 - Agentic coding
    • Xcode 27's app modernization skill can automatically convert mainScreen calls, replace orientation checks with size class checks, and migrate your app to scene lifecycle. Skills can also be exported for use in other tools.

    • 15:32 - Next steps
    • Build with the iOS 27 SDK, test in Device Hub and iPhone Mirroring on macOS 27, identify flexibility gaps in your app, and try the agentic modernization skill.

Developer Footer

  • 视频
  • WWDC26
  • 升级改造你的 UIKit App
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • Mini Apps Partner Program
    • News Partner Program (英文)
    • Video Partner Program (英文)
    • 安全赏金计划 (英文)
    • Security Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则