I have the following view controllers:
Firstviewcontroller
Secondviewcontroller
ThirdViewController
Purpose: Introduce ThirdViewController through SecondViewController.
In FirstViewController, I present SecondViewController using the following method:
[self presentModalViewController:secondViewController animated:NO]
When SecondViewController loads, I present the ThirdViewController in the delegate callback method -viewDidAppear: ::
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self presentModalViewController:thirdViewController animated:NO]; }
So, I think that the circuit for modern controllers is already known to all of us. The code design may not be very good, but I made this solution and have the problem described below.
When ThirdViewController loads, I have problems with 20 points (but only for iOS 4.3, other versions work well).
I added a file that shows my problem.

As you can see on the left, I have an unnecessary offset. After turning the screen, this problem will disappear.
When I print the view frames of the ThirdViewController, it shows me frame = (0 0; 480 300). There may be a problem in the presentation of SecondViewControllers.
About rotation. I have implemented these methods below in each controller:
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) return YES; return NO; }
(UPDATE :) Yes, I found the problem right now, and the frame is SecondViewController = (0 20; 300 480); but I donβt understand why.
I add this method to check the current orientation:
-(void) getCurrentOrientation{ UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; if(orientation == UIInterfaceOrientationPortrait){ NSLog(@"portrait"); } else if(orientation == UIInterfaceOrientationLandscapeRight) { NSLog(@"LandscapeRight"); } else if(orientation == UIInterfaceOrientationLandscapeLeft) { NSLog(@"LandscapeLeft"); } }
and check it in the -viewDidAppear: method, and it shows that the current orientation is a portrait instead of landscape mode, which I configure in the shouldAutorotateToInterfaceOrientation .
In addition, I found that it works well for the iPad iOS 4.3.
I tested everything on the iPhone Simulator.
I added this code to the base view controller, but it still doesn't work for me.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { //Landscape orientation code if (IS_IPAD) { [self.view setFrame:CGRectMake(0, 0, 1024, 748)]; } else if (IS_IPHONE) { [self.view setFrame:CGRectMake(0, 0, 480, 300)]; } else if (IS_IPHONE_5) { [self.view setFrame:CGRectMake(0, 0, 568, 300)]; } NSLog(@"landscape"); NSLog(@"%@", [NSValue valueWithCGRect:self.view.frame]); }else { //portrait orientation code NSLog(@"portrait"); } }
(UPDATE WORK :)
I fixed this problem using the following code:
[UIApplication sharedApplication].statusBarHidden = YES; if (self.thirdViewController) self.thirdViewController = nil; self.thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController"] bundle:nil]; [self presentModalViewController:self.self.thirdViewController animated:NO]; [UIApplication sharedApplication].statusBarHidden = NO;