0

I have a child view controller that needs to be always shown in landscape mode regardless of which mode the parent view is in. I'm adding it onto the parent's view stack with

[[self navigationController] pushViewController:controller animated:NO];

I am trying to force the view to rotate and be displayed as if the device is held in Landscape orientation even though it's still held in Portrait orientation.

The only problem is that no matter what size and coordinates I set the view frame to, I see a 20 pixel gap on the right side of the screen where the StatusBar used to be during Portrait Mode.

What can I adjust to ensure that this gap is gone?

Here's how I'm doing the transformation (as recommended by this SO article)

- (void)changeOrientationToLandscape
{
    UIApplication *myApp = [UIApplication sharedApplication];

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation( degreesToRadian(90) );
    landscapeTransform = CGAffineTransformTranslate(landscapeTransform, +90.0, +90.0 );
    [self.view setTransform:landscapeTransform];

    // Change the status bar orientation so it's shown as if we're in landscape
    myApp.statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

    // Manually force view frame - this doesn't seem to fix the 20 pixel gap
    self.view.frame = CGRectMake(0, 0, 480, 320);
}

The only time I see the view taking up the entire screen and without the 20 pixel gap is if I hide the status bar all together, something I cannot do for this app.

Here's how the screen looks (it's held in Portrait orientation with the home button on the bottom). Notice how the status bar ends doesn't have the same purple background - I was hoping I could shift the view over so the white gap is no longer present.

I also printed out the view and navigationController's view frames and they both report x and y location at 0,0. The navigation view frame's reported dimension is 320x480 while view's frame is 480x320.

View shifted with 20 pixel gap at top

Community
  • 1
  • 1
Jonas Anderson
  • 1,987
  • 4
  • 24
  • 28

2 Answers2

0

What about disabling the status bar when child is pushed and enabling when it's "popped"?

Eduardo Costa
  • 1,974
  • 1
  • 16
  • 22
  • How do you disable the status bar? I only see options to set it hidden or visible. I do need the status bar visible in the child controller. – Jonas Anderson Feb 16 '11 at 17:10
  • If you hide it on parent before pushing the child? I guess you can show it again on children after that (and undone everything when dismissing the children). – Eduardo Costa Feb 16 '11 at 19:01
  • I don't understand. You're saying that I should hide the status bar before the child view is pushed onto the parent nav controller, keep it hidden while the child view is shown, and then display it again when the child view is dismissed? I _need_ to show the status bar in the child view. – Jonas Anderson Feb 16 '11 at 19:17
  • Almost there. If you need to show it, reopen it on child. This seems illogical to do and undo it, but will confirm if it's a bug on your code or on iOS. – Eduardo Costa Feb 16 '11 at 20:18
  • Well the view fills up the entire screen if and only if I keep the status bar hidden in the child view. _However_, no matter what size I set the view frame to be, I cannot resize the view. – Jonas Anderson Feb 16 '11 at 21:15
  • I guess only subviews can be resized. But this behavior seems like a bug. Have you seen any application working like you want? If not, you must fill a bug report. – Eduardo Costa Feb 20 '11 at 18:09
0

You can hide status bar for your child view controller only.

If you're pushing your child view controller via self.navigationController, simply override shouldAutorotateToInterfaceOrientation in child view controller and put this ...

return UIInterfaceOrientationIsLandscape( interfaceOrientation );

... to body of this method to make it landscape only.

zrzka
  • 20,249
  • 5
  • 47
  • 73
  • That doesn't do it because shouldAutoRotate is invoked only after the device's physical orientation changes. In my case, I want to show the view as if the user already rotated to Landscape when in fact, the device is still in Portrait mode physically. – Jonas Anderson Feb 16 '11 at 17:07