iPhone旋转后UINavigationBar消失

时间:2011-08-02 17:47:30

标签: ios uinavigationcontroller rotation uinavigationbar landscape

我有一个应用程序在didFinishLaunchingWithOptions方法中设置UINavigationController,如下所示:

 main_iPhone *mainiPhone = [[main_iPhone alloc] initWithNibName:@"main_iPhone" bundle:nil];
mainiPhone.navigationItem.title = @"TitleHere";

UIBarButtonItem *botaoSobre = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:mainiPhone action:@selector(goToAboutView)];
mainiPhone.navigationItem.rightBarButtonItem = botaoSobre;

navController = [[UINavigationController alloc] initWithRootViewController:mainiPhone];
navController.navigationBar.tintColor = [UIColor orangeColor];
navController.navigationBar.translucent = NO;

[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;

运行应用程序时,导航栏仅在纵向模式下正确显示。但是,当我将设备旋转到横向时,NavigationBar会消失。当我旋转回纵向时,我也不会让NavigationBar回来。

PS:我的mainiPhone.xib文件有2个视图(一个在纵向模式下,一个在横向模式下)。我在mainiPhone.m中切换视图,如下所示:

- (void)willAnimateRotationToInterfaceOrientation:

(UIInterfaceOrientation)interfaceOrientation duration: (NSTimeInterval)持续时间{

if (interfaceOrientation == UIInterfaceOrientationPortrait) {
    self.view = self.portrait; 
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); 
    self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);


} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    self.view = self.landscape; 
    self.view.transform = CGAffineTransformIdentity; 
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); 
    self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);


} else if (interfaceOrientation ==  UIInterfaceOrientationPortraitUpsideDown) { 
    self.view = self.portrait; 
    self.view.transform = CGAffineTransformIdentity; 
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); 
    self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);


} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 

    self.view = self.landscape; 
    self.view.transform = CGAffineTransformIdentity; 
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); 
    self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
}

}

另外,我的shouldAutorotateToInterfaceOrientation方法只返回YES。

我做错了什么? 非常感谢你提前!

0 个答案:

没有答案