【发布时间】:2023-01-19 16:43:07
【问题描述】:
我有两个独立的 iPad 和 iPhone 故事板,它们具有相同的类、插座等,但布局不同。
我发现我可以使用 UIScreen.main.traitCollection.userInterfaceIdiom 在应用程序启动时检测设备类型,但现在我需要调用正确的故事板。我怎么做?我的方向是否正确?我发现与此问题相关的所有内容就像 8-9 年前的帖子,所以有时我什至不理解语法。
提前致谢!
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let iPhoneStoryboard = UIStoryboard(name: "IPhone", bundle: nil)
let iPadStoryboard = UIStoryboard(name: "IPad", bundle: nil)
let type = UIScreen.main.traitCollection.userInterfaceIdiom
switch type {
case .phone:
// need to call something here
case .pad:
// need to call something here
@unknown default:
fatalError()
}
【问题讨论】:
标签: swift xcode storyboard