It's hard for me to imagine ModalViewController in landscape mode. Basically, it is displayed in the correct orientation of the interface and rotates only when the device is held in landscape mode, but the viewcontroller acts as if it is in portrait mode.
I represent the modal style
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; self.window.rootViewController = navController; [self.window makeKeyAndVisible]; LoginViewController *lvc = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]]; [self.window.rootViewController presentModalViewController:lvc animated:NO]; return YES; }
In LoginViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations NSLog(@"%@",NSStringFromCGRect(self.view.frame)); return UIInterfaceOrientationIsLandscape(interfaceOrientation); }
The results of the magazine after several revolutions:
2012-03-06 13:51:49.308 OrientationTest[3132:207] {{0, 0}, {1024, 748}} 2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}} 2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}} 2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}} 2012-03-06 13:51:49.313 OrientationTest[3132:207] {{0, 20}, {1024, 748}} 2012-03-06 13:51:49.314 OrientationTest[3132:207] {{0, 0}, {748, 1024}} 2012-03-06 13:51:49.315 OrientationTest[3132:207] {{20, 0}, {748, 1024}} 2012-03-06 13:51:50.991 OrientationTest[3132:207] {{20, 0}, {748, 1024}} 2012-03-06 13:51:50.991 OrientationTest[3132:207] {{20, 0}, {748, 1024}} 2012-03-06 13:51:51.647 OrientationTest[3132:207] {{20, 0}, {748, 1024}} 2012-03-06 13:51:51.648 OrientationTest[3132:207] {{0, 0}, {748, 1024}} 2012-03-06 13:51:53.481 OrientationTest[3132:207] {{0, 0}, {748, 1024}} 2012-03-06 13:51:53.482 OrientationTest[3132:207] {{0, 0}, {748, 1024}} 2012-03-06 13:51:53.897 OrientationTest[3132:207] {{0, 0}, {748, 1024}} 2012-03-06 13:51:53.898 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
Basically loginViewController acts as if it were in portrait mode. I have two text fields in this view, and when I click one of them, I want to move the view up so that the keyboard does not appear above the text field. To do this, I need to change frame.origin.x instead of y, because the axis is inverted (the view acts like a portrait), and this causes a lot of problems.
Edit:
If I change the modal presentation style on LoginViewController to UIModalPresentationPageSheet, it works as intended, so there is a problem only with full screen mode
Second edit:
I split the code into the basics. I don’t even imagine the modal view controller anymore, just by initializing this view controller as the root view controller, and yet this happens.
Application Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; }
In my opinion, the controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations NSLog(@"%@",NSStringFromCGRect( self.view.frame)); return UIInterfaceOrientationIsLandscape(interfaceOrientation); }