简体   繁体   English

尺寸等级和不同的控制器

[英]Size Classes and Different Controllers

I have the need to show a different view controller for compact vs regular size classes. 我需要为紧凑型和常规尺寸的类显示不同的视图控制器。 The difference in views is too great for the regular use case. 对于常规用例,视图的差异太大。 My app used to just work based off of iPad Storyboard vs iPhone Storyboard. 我的应用程序以前只能在iPad Storyboard和iPhone Storyboard的基础上工作。 On an iPhone it shows some text, and on an iPad it shows a PDF. 在iPhone上,它显示一些文本,在iPad上,它显示PDF。 Would I have to do this in code, by creating a different container view controller, or are Size Classes not the tool for this? 我将不得不通过创建另一个容器视图控制器来在代码中执行此操作,还是不是尺寸类用于此目的的工具?

I guess the better way to do this is by using separate storyboard for iPhone and iPad. 我想更好的方法是通过为iPhone和iPad使用单独的故事板。 We mainly use Size classes to have minor changes in UI element positions and constraints. 我们主要使用Size类对UI元素位置和约束进行细微更改。

You can set the iPhone and iPad storyboards in your .plist using the keys 您可以使用键在.plist中设置iPhone和iPad故事板

Main storyboard file base name (iPhone) 主故事板文件的基本名称(iPhone)

Main storyboard file base name (iPad) 主故事板文件基本名称(iPad)

Or if it is just one ViewController, then you can set it through code. 或者,如果只是一个ViewController,则可以通过代码进行设置。 Set two different view controllers in storyboard and instantiate the appropriate one based on size class. 在情节提要中设置两个不同的视图控制器,并根据大小类实例化相应的视图控制器。 To identify your current size class, use my answer in Universal storyboard UITableview row Height . 要确定您当前的尺寸等级,请在Universal Storyboard UITableview row Height中使用我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM