IOS 4.3 UI Orientation Problem with 20 Status Bar Dots

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.

enter image description here

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; 
+4
source share
2 answers

Alexander, could you try under the code. This works in 4.3 (adding to SecondViewController):

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; [UIApplication sharedApplication].statusBarHidden = YES; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; AMThirdViewController* th = [[AMThirdViewController alloc] initWithNibName:nil bundle:nil]; [self presentModalViewController:th animated:NO]; [UIApplication sharedApplication].statusBarHidden = NO; } 
+1
source

The SecondViewController frame (0, 20; 300, 480) instead of (0, 0; 320, 480) due to the status bar at the top of the screen. Thus, either you can remove the status bar from the "Attributes inspector" by setting it to "none", or you can adjust the view frame to

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (UIInterfaceOrientationIsLandscape(orientation)) { //Landscape orientation code }else { //portrait orientation code } } 

method.

0
source

All Articles