Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISplitViewController always show master view in iPad portrait mode iOS 9

I'm building a universal app using UISplitViewController and targeting iOS 9 and above. The app language is Objective-C.

Having started with the Xcode Master/Detail template and set up my views in the standard way, I'm realising that the app will be better if I keep the master view on screen at all times (on iPad), including when the device is in portrait mode. However, no matter how hard I search, I can't find anything to help me learn how this is achieved. I know this was previously achieved using splitViewController:shouldHideViewController:inOrientation:

However, this method is deprecated in iOS 9 and I can't figure out what replaces it and why. I've looked at the new delegate methods for UISplitViewController and find them completely lacking in any level of intuitiveness.

I'd really appreciate some pointers in regard to what replaces splitViewController:shouldHideViewController:inOrientation: and how it can be used to keep the master view displayed at all times on the iPad.

like image 500
beev Avatar asked Feb 16 '16 18:02

beev


2 Answers

Subclass UISplitViewController

There is no need to specifically track orientation changes: Master and Detail will still be displayed in sequence on iPhone in portrait mode, and most iPhone in landscape mode.
preferredDisplayMode:.allVisible only affects the modes where both views can be simultaneously visible.

Swift

class SplitViewController: UISplitViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        preferredDisplayMode = .allVisible
    }
}

Obj-C

- (void)viewDidLoad {
    [super viewDidLoad];
    self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;

}

iPad Portrait & iPhone 8 Plus Landscape

enter image description here

like image 129
SwiftArchitect Avatar answered Oct 11 '22 01:10

SwiftArchitect


If anybody checks this topic lately the .allVisible was deprecated in IOS 14, use this: splitVC.preferredDisplayMode = .oneBesideSecondary

aSplitViewController.preferredDisplayMode = .oneBesideSecondary

like image 45
Akos Farkas Avatar answered Oct 11 '22 01:10

Akos Farkas