Storyboards + size classes: how to implement different Segues, ViewControllers, UserFlow for different device classes / classes?

The existing iOS 7+ application supports iPhone and iPad. I am currently using two different storyboards for the layout of the iPhone and iPad, which works great. Now I'm trying to convert this to a single-line layout using adaptive size classes.

My problem is that my iPhone and iPad layouts are completely different. They not only use different sizes and positions for their controls, but also some completely different view controllers.

Both storyboards use MMDrawerController as the starting VC. But from there the flow of control is different. While the iPad Storyboard uses the UISplitViewController as the base for all other ViewControllers, the iPhone uses the UITabBarViewController instead.

This is only one difference, but there are others. How should these differences be handled in a single storyboard? To achieve this, I would have to make various differences depending on the current size class. But as far as I know, this is impossible.

Some of the new adaptive Segues iOS 8 may behave differently depending on the size class, but as far as I know, it is not possible to specify different segments for different class classes. In addition, it is not possible to define different initial ViewControllers depending on the size class.

So the question is: Is it possible to specify two different layouts (including different Segues, ViewControllers, etc.) in the same storyboard?

The reason for switching to one storyboard is the support of the new Split Screen and Slide Over features in iOS 9. Downloading different storyboards at startup depending on the screen size / class size is simple. But switching to another storyboard at runtime when the dimension class changes dynamically is not possible. It?

+7
ios iphone uiviewcontroller ipad size-classes
source share
1 answer

I just experienced this kind of pain and found that the only real way to deal with the big differences is to create separate controllers and segues in the storyboard, as usual, but to execute them in the code and not to use the segue activation created in the storyboard.

In my case, I used the side menu on the iPhone and iPad, but the iPad used split view controllers for the main display and the UINavigationController on the iPhone. An additional complication is that on iOS8, the UISplitViewController is supported on the iPhone, but not on iOS7, where it is considered as the UINavigationController.

As far as I know, you cannot use the size class to automatically start a segment of the desired type. However, you can do this in code if you have a mechanism to choose from. Thus, you can create segues for each size class or better your display mode for a certain type of device and call the correct code.

The biggest problem is the iOS9 split screen, which seems to dynamically change the size class from iPad regularW / regularH to iPad compactW / regularH and vice versa when scrolling. You'll be fine for things like split views, which will just switch to look like a navigation controller stack. I do not see any way, however, to switch to the tab bar, they say "on the fly", if you do not return to the root directory, ask the application delegate to switch the root screen and transfer you back to the same place. Much will depend on what you want to see in this case.

As a result, my general rule in the storyboard was:

0) In the application delegate, determine the type of device and set the root screen as the correct entry point for the schedule controller: for example, split view on ipad, view tabs on iPhone. It is convenient to add some methods / properties to the application delegate to access any controller to search for the current operating mode. This will make life easier later when you need to decide which one to shoot.

1) Create custom controllers as needed and always use the Any / Any size construct to create the bulk of the design. I started using a variety of design looks, but found it too difficult to manage. Moreover, some controllers can appear in popovers, where the size class on the iPad (compact width) does not match what is on the main screen (normal width).

2) Use size class settings for individual restrictions, fonts, etc., if necessary.

3) For any view controller that may appear in a popover, it is preceded by a UINavigationController with a storyboard identifier that can be used as the root of any popover.

4) For UISplitViewControllers, create as usual using the showDetail style segments.

5) For UIViewControllers, which are used as detailed views in controllers with separate views, but which may also be required for inclusion when used in popover or on iPhone on iOS7, create push segments from the corresponding controllers of the main parts. You only need this if you are each content created in the form of a split through a popover or when on iOS7, which does not have a split view on the iPhone.

6) Create segments between your controllers, including specific iPad / iPhone segments. You can use storyboard activation if there is only one indent possible. Otherwise, just draw segments between the controllers themselves.

7) For any controllers where buttons or cells trigger segments, you add target actions, not segue triggers. In these steps, you will call the corresponding segment manually.

8) In each view controller, where the type of destination controller depends on the type of display mode, write a code that uses the properties of the application delegate mode to decide which session to use and then call peformSegueWithIdentifier using the segment identifier.

Not especially, but it seems evil, especially if you use partition controllers and popovers. It’s good that you can at least see everything in one place.

+4
source share

All Articles