Why does [UIViewController presentModalViewController: animated:] translate the modal view on the left?

I am creating an application that only supports landscape orientation on the iPad under iOS 4.3, although the error was also present in iOS 4.2.

A few places in the application, I show the UIViewController as modal views. All of them are shown using this template:

 viewController.modalPresentationStyle = UIModalPresentationFormSheet; viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentModalViewController:viewController animated:YES]; 

In most cases, they work as expected β€” the modal shape of the sheet slides up from the bottom of the screen.

However, in two cases, the sheet of modal shape moves in the lower left corner of the screen. The form sheet slides almost completely to the right, and the bottom of the form sheet goes out of view. If you focus the text field and show the on-screen keyboard, the form sheet moves to the upper center of the screen, where you expect it to be.

I don’t think that simulated XIB metrics influence their behavior, but I set the orientation for all of them (both the calling UIViewController self and the modal view controller viewController ) in landscape orientation.

Any ideas why these two modal form sheets behave differently than the others?

+4
source share
2 answers

I think that here you are returning the landscape orientation to the shouldAutorotate function, so use this code if you want to see the landscape left / right:

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

Try this, it can help you.

0
source

Make sure you have a viewController built into the NavigationController, that navController shouldAutotorate also matters

0
source

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


All Articles