Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPad UINavigationController Landscape problem

I am having a problem in presenting UINavigationViewController in landscape mode. The view is automatically rotated to portrait mode. I already spent around 3 hours solving on this issues. It is working fine if I present without navigation controller. But, I need navigation controller because I have to push another viewcontroller from that.

Please suggest anything to fix the issue. Here's the code.

SharingViewController *sharingViewController = [[SharingViewController alloc] initWithNibName:@"SharingViewController" bundle:nil];

    UINavigationController *navi = [[[UINavigationController alloc] initWithRootViewController:sharingViewController] autorelease];

    [navi setWantsFullScreenLayout:YES];
    [navi.view setAutoresizesSubviews:NO];
    [navi.navigationBar setHidden:YES];
    navi.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    navi.visibleViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentModalViewController:navi animated:YES];
like image 619
Min Soe Avatar asked Sep 19 '26 16:09

Min Soe


1 Answers

If you do this:

SharingViewController *sharingViewController = [[SharingViewController alloc] initWithNibName:@"SharingViewController" bundle:nil];
sharingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;

UINavigationController *navi = [[[UINavigationController alloc] initWithRootViewController:sharingViewController] autorelease];
navi.modalPresentationStyle = UIModalPresentationCurrentContext;
...

[[self navigationController] presentModalViewController:navi animated:YES];

it should work. I had same problem, but when I added modalPresentationStyle property to viewController and to UINavigationController it started working.

like image 60
Josip B. Avatar answered Sep 22 '26 21:09

Josip B.