简体   繁体   中英

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. On an iPhone it shows some text, and on an iPad it shows a 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. We mainly use Size classes to have minor changes in UI element positions and constraints.

You can set the iPhone and iPad storyboards in your .plist using the keys

Main storyboard file base name (iPhone)

Main storyboard file base name (iPad)

Or if it is just one ViewController, then you can set it through code. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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