Problems with modal view launched over a split view controller

一笑奈何 提交于 2019-12-10 07:14:14

问题


I have created a split view application that begins with a modal view splash page. The problem is that the modal view always launches in portrait mode, even if the ipad is in landscape. If I rotate the ipad a couple of times, it rotates appropriately. I have set UIInterfaceOrientation in my Info.plist, but it doesn't have any impace.

in didFinishLaunchingWithOptions, I am using 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 ensure the modal view launches in landscape?


回答1:


I think this is the better way to do it:

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



回答2:


I had a similar problem when using Matt Gemmell's MGSplitViewController. In my case, by trying to open a modal view controller in FormSheet mode from inside the detail view controller (that is the "right" pane in the UISplitViewController standard), my modal view was forcing interface rotation to portrait. I found the solution by overriding the modal view controller -> shouldAutorotateToInterfaceOrientation: and letting him returning a NO:

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

In this way when the modal is going to be presented, for some reason the OS tries to force it to portrait. By answering NO the view is no more rotated and everything works fine.




回答3:


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

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

Good luck.

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



来源:https://stackoverflow.com/questions/4750813/problems-with-modal-view-launched-over-a-split-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!