Xcode 9 布局:有没有一种方法可以为 iPad 构建一个与 iPhone 内容相同的新故事板?
Xcode 9 Layout: Is there a way to build a new storyboard with the same content from the iPhone just for the iPads?
我在为所有设备获取带约束的布局时遇到问题,所以我的问题是,是否有一种方法可以使用相同的代码、segues 等为 iPad 构建额外的故事板,这样会更容易正确获取布局。
是的,有办法,您可以复制现有故事板并将其重命名为 iPad_Main.storyboard
,然后您必须更正一些约束或更改适合 iPad 屏幕的值。
之后,在初始化任何视图控制器之前,您必须检查设备是 iPad 还是 iPhone,并且基于此您必须使用故事板。
let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
let storyboard : UIStoryBoard!
if (deviceIdiom == .pad) {
storyboard = UIStoryboard(name: "iPad_Main", bundle: nil)
}
else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
// Use storyboard to get desired controller using StoryboardID of UIViewController
我在为所有设备获取带约束的布局时遇到问题,所以我的问题是,是否有一种方法可以使用相同的代码、segues 等为 iPad 构建额外的故事板,这样会更容易正确获取布局。
是的,有办法,您可以复制现有故事板并将其重命名为 iPad_Main.storyboard
,然后您必须更正一些约束或更改适合 iPad 屏幕的值。
之后,在初始化任何视图控制器之前,您必须检查设备是 iPad 还是 iPhone,并且基于此您必须使用故事板。
let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
let storyboard : UIStoryBoard!
if (deviceIdiom == .pad) {
storyboard = UIStoryboard(name: "iPad_Main", bundle: nil)
}
else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
// Use storyboard to get desired controller using StoryboardID of UIViewController