Do we need to use 2 Storyboard for a Universal app?

前端 未结 6 1743
星月不相逢
星月不相逢 2021-02-06 12:01

I have a project for iPhone and iPad. The iPad needs a split view controller. Do we create two separate storyboards? One for iPhone (using autolayout we can support all devices)

相关标签:
6条回答
  • 2021-02-06 12:42

    I managed to have that scenario (split controller in an universal storyboard that works on both iOS8 and iOS7) by calling a different segue while on iOS7 and iPhone. My scenario is like this:

    I have a login controller that is supposed to segue to a main controller (modally).

    When on iOS8 or iPad I use a segue points to the split view controller, while when on iOS7-iPhone I use another segue that points directly to the left nav controller of the split controller (bypassing it entirely).

    If from the left controller you have a detail segue that points to the right nav controller(and you should) and if the segue type is "Show Detail" (and it should) then it will perform like a regular push in the iOS7-iPhone environment (which is exactly what we want).

    On thing I noticed though, the detail segue's destination controller in the IOS7-iPhone scenario becomes the root view controller of the right nav (even though the segue is pointing to the nav), therefore, if you have some code in the prepareForSegue you might need to adapt it to handle them differently)

    (For determining if the platform is IOS8 and if I'm on iPhone/iPad idiom I use the standard

    [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 and UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    
    0 讨论(0)
  • 2021-02-06 12:52

    For iOS 7 and before, yes, use two storyboards and two completely different interfaces, since there is no split view controller on the iPhone.

    For iOS 8, use one storyboard, and use the UISplitViewController on both the iPad and the iPhone. Make a new project from the Universal version of the Xcode 6 Master-Detail app template to see all about how it works! It is automatically a split view controller on the iPad and a navigation interface on the iPhone.

    0 讨论(0)
  • 2021-02-06 13:01

    On iOS 8, you do not need two storyboards since a single storyboard can handle both iPhone and iPad; also, UISplitViewController is supported on the phone on that OS.

    For earlier releases of iOS, you'll need two storyboards.

    0 讨论(0)
  • 2021-02-06 13:02

    You can have many more than just two storyboards. If you are unable to us size classes / auto layout to accomplish the job of a view controller shared between iPhone and iPad, you can split that part into separate storyboards. You can then create a third storyboard which holds the view controllers that are shared. You can then instantiate that storyboard in code and use it to instantiate its view controllers.

    0 讨论(0)
  • 2021-02-06 13:06

    No need for two storyboards any more in iOS 8! We can use Adaptive UI in order to tailor the same storyboard all different sizes of iPad and iPhone.

    You can find a nice tutorial in here http://www.raywenderlich.com/83276/beginning-adaptive-layout-tutorial

    And also you can find a nice video by apple in WWDC conference here and search for "Building Adaptive Apps with UIKit"

    Basically we can handle different screen sizes by defining elements of our UI in storyboard for different size classes. We can also define different Auto layout constraints for different size classes.

    And these are all possible size classes in iOS 8 ( I took the image from https://medium.com/@getaaron/ios-8-development-tips-for-iphone-6-and-iwatch-1c772554ffe0)

    enter image description here

    0 讨论(0)
  • 2021-02-06 13:07

    Even with adaptive UI, personally I prefer to work on different storyboard. For complex layout it is easier this way and it will not easily break the layout for other screen size. Having too many constrain can make harder to maintain. Also moving the object hierarchy will break the layout for other screen.

    As bonus, if you work with low level mac like mackbook air or old mac, it also reduce the load time and get better responsiveness when you work with storyboard.

    0 讨论(0)
提交回复
热议问题