我有一个应用程序,它以根UINavigationController
开头。这个控制器然后推动和弹出其他各种UIViewControllers
- 这一切都正常工作。UINavigationbar在旋转时丢失了设置图像
我的应用程序有一个navigationController.navigationBar.backgroundImage
的自定义图形。 iPhone平台有一个图像。 iPad平台有两个图像 - 一个用于肖像,一个用于景观。 iPad在旋转时是问题的平台,iPhone平台只是肖像。
我已经编写了代码-(void)willRotateToInterfaceOrientation:
来检测旋转,并将navigationBar.backgroundImage
设置为正确的方向图形(如果平台是iPad的话)。
在iPad 5.0模拟器 - 它工作正常;在屏幕上旋转iPad会导致无论方向如何都会显示正确的导航栏图形。
在设备上 - 它不起作用 - 图形在iPad设备以纵向启动时正确显示。当我旋转到横向时,导航栏更改为标准的灰色。当我旋转灰色的“棍子”。
我试过拨打setNeedsDisplay
- 没有变化。
我试过设置navigationBar.tintColor = [UIColor clearColor]
- 没有改变。
我检查了代码中图形的文件名与实际文件名相同 - 它们是。
代码旋转:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return YES; }
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
UIImage *titleImage = [UIImage imageNamed:@"StandardHeaderIpadLandscape"];
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:titleImage forBarMetrics:UIBarMetricsDefault];
self.navigationController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"StandardBackgroundiPadLandscape.png"]];
[self.navigationController.navigationBar setNeedsDisplay];
} else {
UIImage *titleImage = [UIImage imageNamed:@"StandardHeaderIpadPortrait"];
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:titleImage forBarMetrics:UIBarMetricsDefault];
self.navigationController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"StandardBackgroundiPad.png"]];
[self.navigationController.navigationBar setNeedsDisplay];
}
}
}
向我们展示旋转方法。检查'navigationBar'是否为零。之后,我们可以讨论其他潜在的问题。 – an0 2012-01-07 14:17:05
谢谢,我已经添加了上面的代码。我检查了NSLog的存在,它确实存在。 – Skybird 2012-01-07 14:33:50
如果您在横向上启动应用程序,会发生什么情况?那么图像会在那种情况下显示出来吗? – Bek 2012-01-07 15:07:06