UIScene 如何适配

Asked on 06/13/2025

1 search

To adapt UIScene in your UIKit app, you can follow several strategies discussed in the WWDC sessions:

  1. UI Scene Size Restrictions: You can use the UI Scene Size Restrictions API to express the preferred minimum size of your scene's content. This is particularly useful when your app requires a minimum size to maintain core functionality. The best time to specify the minimum size is when the scene is about to connect. For example, you might specify a preferred minimum width of 500 points. This ensures that your app remains flexible and adaptable to different screen sizes. Make your UIKit app more flexible.

  2. Scene Lifecycle: Adopting the UI Scene lifecycle is crucial for building flexible applications. This lifecycle allows each scene to independently save and restore its UI state, providing a strong foundation for flexibility. It's important to handle state restoration to ensure the UI state of a connecting scene is exactly how it was left before. Make your UIKit app more flexible.

  3. Adaptivity: Ensure that your UI is adaptable by keeping content within the safe area and using layout guides to account for window controls. This helps in making sure that your UI is not occluded by system UI elements or device features. Make your UIKit app more flexible.

  4. Mixing SwiftUI and UIKit: In iOS 26, you can mix SwiftUI and UIKit scene types in a single app, which enhances the flexibility and adaptability of your app. This allows you to leverage the strengths of both frameworks. Make your UIKit app more flexible.

These strategies are part of the broader effort to make UIKit apps more flexible and adaptable to various device configurations and user needs.