如何确保两个屏幕只支持人像模式?
How do I make sure that two screens only support Portrait mode?
因此,在我正在处理的应用程序中,我必须创建 2 个视图控制器,一个支持 iPad 布局,一个支持 iPhone 布局。但是,我的故事板不支持横向模式。
我的部署信息:https://imgur.com/G78mDzn
我的 info.plist 的一部分:https://imgur.com/8cdj2pU
请注意,在 iPads 上运行的版本有 iPadStoryboard.storyboard,在 iPhones 上运行的版本有 Main.storyboard。
phone 可以满足我的要求 – 它不会变成横向。
然而,iPad 并没有做同样的事情。我该如何解决?
如何以编程方式进行?
在AppDelegate.swift
、
定义var storyboard: UIStoryboard!
在func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
之下
switch UIDevice.current.userInterfaceIdiom {
case .phone, .unspecified:
// It's an iPhone, or anything else like AppleWatch, AppleTV
storyboard = UIStoryboard(name: "Main", bundle: nil)
case .pad:
// It's an iPad
storyboard = UIStoryboard(name: "iPadStoryboard", bundle: nil)
}
然后在您的应用中使用这个故事板来初始化您的视图控制器。
如果它只适用于一个或两个屏幕,请在您的控制器文件中尝试此操作
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
在您的部署信息中,将设备更改为 iPad
取消选中横向
因此,在我正在处理的应用程序中,我必须创建 2 个视图控制器,一个支持 iPad 布局,一个支持 iPhone 布局。但是,我的故事板不支持横向模式。
我的部署信息:https://imgur.com/G78mDzn
我的 info.plist 的一部分:https://imgur.com/8cdj2pU
请注意,在 iPads 上运行的版本有 iPadStoryboard.storyboard,在 iPhones 上运行的版本有 Main.storyboard。
phone 可以满足我的要求 – 它不会变成横向。
然而,iPad 并没有做同样的事情。我该如何解决?
如何以编程方式进行?
在AppDelegate.swift
、
定义var storyboard: UIStoryboard!
在func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
switch UIDevice.current.userInterfaceIdiom {
case .phone, .unspecified:
// It's an iPhone, or anything else like AppleWatch, AppleTV
storyboard = UIStoryboard(name: "Main", bundle: nil)
case .pad:
// It's an iPad
storyboard = UIStoryboard(name: "iPadStoryboard", bundle: nil)
}
然后在您的应用中使用这个故事板来初始化您的视图控制器。
如果它只适用于一个或两个屏幕,请在您的控制器文件中尝试此操作
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
在您的部署信息中,将设备更改为 iPad 取消选中横向