Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UINavigationBar在iPhone旋转后消失_Ios_Uinavigationcontroller_Rotation_Uinavigationbar_Landscape - Fatal编程技术网

Ios UINavigationBar在iPhone旋转后消失

Ios UINavigationBar在iPhone旋转后消失,ios,uinavigationcontroller,rotation,uinavigationbar,landscape,Ios,Uinavigationcontroller,Rotation,Uinavigationbar,Landscape,我有一个应用程序可以在didFinishLaunchingWithOptions方法中设置UINavigationController,如下所示: main_iPhone *mainiPhone = [[main_iPhone alloc] initWithNibName:@"main_iPhone" bundle:nil]; mainiPhone.navigationItem.title = @"TitleHere"; UIBarButtonItem *botaoSobre = [[UIB

我有一个应用程序可以在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;
- (void)willAnimateRotationToInterfaceOrientation:
运行应用程序时,导航栏仅在纵向模式下正确显示。但是,当我旋转设备以横向移动时,导航栏消失。当我旋转回到纵向时,导航栏也不会回来

PS:My mainiPhone.xib文件有两个视图,一个在纵向模式,一个在横向模式。我在主iPhone内切换视图。m如下所示:

 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;
- (void)willAnimateRotationToInterfaceOrientation:
UIInterfaceOrientation界面定向持续时间: 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

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

如果我添加UINavigationController*navC=[self-navigationController];作为WillAnimateRotationInterfaceOrientation方法的第一行,它返回nil。不知何故,当设备旋转时,我在didFinishLaunchingWithOptions方法中创建的导航控制器丢失了,但我不知道为什么。