Modal view issues running through split view controller

I created a split view application that starts with a splash page of a modal view. The problem is that the modal view always starts in portrait mode, even if the ipad is in landscape. If I rotate the ipad several times, it rotates accordingly. I set UIInterfaceOrientation to my Info.plist, but it has no impace.

in didFinishLaunchingWithOptions , I use the following code

... [self.window addSubview:splitViewController.view]; SplashViewController *modalView = [[SplashViewController alloc] intiWithNibName:nil bundle:nil]; modalView.modalPresentationStyle = UIModalPresentationFullScreen; [splitViewController presentModalViewController:modalView animated:YES]; ... 

Any suggestions on how I can guarantee that the modal view runs in the landscape?

+4
source share
3 answers

I think this is the best way to do this:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) { return YES; } return NO; } 
+1
source

I had a similar problem when using Matt Gemmell MGSplitViewController . In my case, trying to open the modal view controller in FormSheet mode from the inside of the detail view controller (this is the "right" panel in the UISplitViewController standard), my modal view made the interface rotate to the portrait. I found a solution by overriding the modal view controller -> shouldAutorotateToInterfaceOrientation: and letting it return NO:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Overriden to allow any orientation. return NO; } 

Thus, when the modal is presented, for some reason the OS is trying to force it to make a portrait. Answering NO, the view no longer rotates, and everything works fine.

+1
source

In the file from which you start the modal view, you will want to change / override the following function. You can simply copy and paste the following code, and you can start the modal view in landscape portrait mode:

 - (BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } 

Good luck.

EDIT: I said portrait mode instead of what I meant: landscape mode.

0
source

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


All Articles