Modal View controller will not start in landscape mode

I have a navigation based application that has a detailed view (UIWebView) with action buttons at the bottom in a UIToolbar. I want to add β€œnotes” when the β€œNotes” button is pressed. Everything works fine when web browsing is in portrait mode. I press the notes button, the modal view opens perfectly and works great.

The problem occurs when the web view is in landscape mode. If I click on the "Notes" button, all the code is called to open the modal view, but all I get is a white screen. One comment. If I open the modal view in the portrait and then rotate the device, it rotates perfectly in landscape mode. It just won’t open correctly in landscape mode.

I have another button that calls the mail composer that has the same behavior. Here is the code of my UIWebViewController:

- (IBAction)addNotes:(id)sender { NotesViewController *notesViewController; // create the view controller and set it as the root view of a new navigation // controller notesViewController = [[NotesViewController alloc] initWithPrimaryKey:self.record.primaryKey]; UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:notesViewController]; // present the navigation controller modally [self presentModalViewController:newNavigationController animated:YES]; [notesViewController release]; [self.view setNeedsDisplay]; // not sure if I need this! I was trying different things... [self.devotionText setNeedsDisplay]; // ditto... [newNavigationController release]; } 

Any ideas? I tried all kinds of things to no avail. I just get a white screen without a navigation bar (although there is a status bar at the top).

+6
iphone xcode modalviewcontroller
source share
7 answers

Modals do not always receive information about turns, and they get their information from the status bar, which does not always work correctly. Put this in your WillAppear view to fix: [UIApplication sharedApplication].statusBarOrientation = self.interfaceOrientation And, if you want a controller to be created in your modal navigation controller, you need to create it.

Also, you do not need setNeedsDisplay. This only affects current views, not what you represent.

+7
source share

The answer is here:

fooobar.com/questions/873685 / ...

 Use the window root view controller to present: [self.view.window.rootViewController presentViewController:masterView animated:YES completion:NULL]; 
+4
source share

Wow, I lost days over this problem ... but I found a solution!

I had the same problem as yours: the "presentModalViewController: animated:" method worked only in portrait mode.

After a lot of trial and error, I found out that the reason is because I had several view controllers at the same time. I implemented a navigation system that switched between different view controllers, with one of the parents handling the children. (I could not use the UINavigationController because I needed a different look.)

So, my root view controller had a root view object and several child view controllers. When the child view controller was activated, its view object was added as a view in the view controller's root view.

The "presentModalViewController" method did not like. However, as soon as I set the parentViewController property of the child controllers, it will work!

The only problem is that the "parentViewController" is a read-only property. You must extend the UIViewController class so that you can access it.

 @interface UIViewController (HelperExtension) @property (nonatomic, assign) UIViewController *parent; @end @implementation UIViewController (HelperExtension) - (UIViewController *)parent { return self.parentViewController; } - (void)setParent:(UIViewController *)parent { [self setValue:parent forKey:@"_parentViewController"]; } @end 

So, whenever you add a child view controller view to your parent view controller, call the "setParent:" method after that. Then it will work!

+2
source share

It turns out the same problem when presenting a modally navigation controller. Remember to execute correctly: shouldAutorotateToInterfaceOrientation

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { BOOL shouldAutorotate = NO; if( isControllerMangingAllOrientations ) { shouldAutorotate = YES; } else { shouldAutorotate = (toInterfaceOrientation == UIInterfaceOrientationPortrait); } return shouldAutorotate; } 

I set a boolean in the viewDidLoad method, but this is not a good idea. Put it in the initWithNibName: bundle: method - this is the right place.

+2
source share

If you use presentModalViewController only for animations like me, you can use pushViewController with animations as shown below:

Pushviewcontroller animation display looks like presentModalViewController

and you can close the viewController as shown below;

 CATransition* transition = [CATransition animation]; transition.duration = 0.3; transition.type = kCATransitionFade; transition.subtype = kCATransitionFromTop; [self.navigationController.view.layer addAnimation:transition forKey:kCATransition]; [self.navigationController popViewControllerAnimated:NO]; 

Hope this helps.

0
source share

I had the task of showing the video player in landscape mode.

 AVPlayerViewController *playerViewController = [AVPlayerViewController new]; //Player init code goes here.... // #define degreesToRadian(x) (M_PI * (x) / 180.0) - was defined previously in a class header playerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; playerViewController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); playerViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); [self presentViewController:playerViewController animated:YES completion:nil]; 
0
source share

You do not need a new Navigation Controlle r.

 - (IBAction)addNotes:(id)sender { NotesViewController *notesViewController; // create the view controller and set it as the root view of a new navigation // controller notesViewController = [[NotesViewController alloc] initWithPrimaryKey:self.record.primaryKey]; [self.navigationController pushViewController: notesViewController animated: YES]; [notesViewController release]; } 
-one
source share

All Articles