Rotating the split screen controller on the iPhone 6 Plus

I have a split view controller in landscape mode with two navigation controllers.

enter image description here

This collapses to a single navigation controller in the portrait, and the detailed view controller is pushed out of the wizard.

enter image description here

If I turn back to the landscape when the detail view controller is pressed in the portrait, I don’t understand how to return the detail view controller to my own navigation controller.

enter image description here

+5
source share
1 answer

You must implement the UISplitViewControllerDelegate. The easiest way is to have your own MySplitViewController class and designate yourself as a delegate in viewDidLoad:

self.delegate = self; 

First, you might want showDetailViewController to look something like this:

 - (BOOL) splitViewController:(UISplitViewController*)splitViewController showDetailViewController:(UIViewController*)vc sender:(id)sender { if (splitViewController.collapsed) { [(UINavigationController*)splitViewController.viewControllers[0]) pushViewController:vc animated:YES]; } else { self.viewControllers = @[ self.viewControllers.firstObject, vc ]; } return YES; } 

This should take care of the correct presentation of the detail representation in both orientations.

Next, you must implement the following delegation method, similar to this:

  - (UIViewController*) splitViewController:(UISplitViewController*)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController*)primaryViewController { UINavigationController* nc = primaryViewController; UIViewController* detailVC = nc.viewControllers.lastObject; return detailVC; } 

This method is your chance to take everything you want from the main controller and return it as the controller of the detailed views. The above sample example is pretty simple, you may have to go through the viewControllers navigation and select everything from a specific view controller (if you clicked on the view details).

In any case, it would actually be beneficial to spend some time and read: a link to the UISplitViewController class and especially the UISplitViewControllerDelegate Protocol Reference This will be much clearer. If you need a shortcut, take a look at the Xcode splitting controller template project. It should also contain a hint or an exact solution to your problem.

+4
source

Source: https://habr.com/ru/post/1212772/


All Articles