views:

250

answers:

1

Hi,

I'm rotating a view similar to tje iTunes app. In portrait is a tableview and in landscape is photo viewver.

When I return from landscape to portrait I try to recover the navigationbar but instead get a distorted tableview, and no navigation bar.

This is what I do:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
       duration:(NSTimeInterval)duration {
BOOL restoreNav = NO;

if ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || 
 (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
 [self inPortrait];
 restoreNav = YES;
} else {
 [self inLandscape];
}

if (self.landscape)
{
 if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
 {
  self.view = self.portrait;
 }
 else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
 {
  self.view = self.landscape;
 }
 else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
 {
  self.view = self.portrait;
 }
 else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
 {
  self.view = self.landscape;
 }  
 [[self.navigationController view] setFrame: [[UIScreen mainScreen] bounds]];
} else {
 self.navigationController.navigationBarHidden = NO; 
}

[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
+1  A: 

I found a semi-fix for this in http://www.iphonedevsdk.com/forum/iphone-sdk-development/3262-horrible-drawing-after-hiding-navigationbar.html

This is the relevant code:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
//total hack - to fix the bug where the screen layout is shagged if the device orientation
//is changed when the navigation is hidden

if ([self.navigationController isNavigationBarHidden])
{
 [self.navigationController setNavigationBarHidden:NO animated:NO];
 [self.navigationController setNavigationBarHidden:TRUE animated:NO];
}

}

However, is messy again if a show up the nav bar.

mamcx