Objective c UINavigationbar在旋转时丢失设置的图像
我有一个以rootObjective c UINavigationbar在旋转时丢失设置的图像,objective-c,uinavigationcontroller,rotation,navigationbar,Objective C,Uinavigationcontroller,Rotation,Navigationbar,我有一个以rootUINavigationController开头的应用程序。然后,该控制器推送并弹出各种其他UIViewControllers——一切正常 我的应用程序为navigationController.navigationBar.backgroundImage提供了自定义图形。iPhone平台有一张图片。iPad平台上有两张图片——一张是纵向的,一张是横向的。iPad在旋转时是问题的平台,iPhone平台只是一个肖像 我已经在-(void)willRotateToInterfaceO
UINavigationController
开头的应用程序。然后,该控制器推送并弹出各种其他UIViewControllers
——一切正常
我的应用程序为navigationController.navigationBar.backgroundImage
提供了自定义图形。iPhone平台有一张图片。iPad平台上有两张图片——一张是纵向的,一张是横向的。iPad在旋转时是问题的平台,iPhone平台只是一个肖像
我已经在-(void)willRotateToInterfaceOrientation:
中编写了代码来检测旋转,并将导航栏.backgroundImage
设置为正确的方向图形(如果平台是iPad)
在iPad5.0模拟器中——工作正常;无论方向如何,在屏幕上旋转iPad都会产生正确的导航栏图形
在设备上-它不工作-图形在iPad设备启动时正确显示为纵向。当我旋转到横向时,导航栏变为标准灰色。当我旋转回灰色的“棍子”
我已尝试呼叫setNeedsDisplay
-无更改
我已尝试设置navigationBar.tintColor=[UIColor clearColor]
-没有更改
我已经检查了代码中图形的文件名是否与实际文件名相同-它们是相同的
轮换代码:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return YES; }
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}检查
标题图像是否为零。我感觉您的图像路径不正确,或者这些图像没有正确复制到iPad。告诉我们旋转方法。首先检查navigationBar
是否为零。之后,我们可以讨论其他可能涉及的问题。谢谢,我已经添加了上面的代码。我用NSLog检查了它是否存在,它确实存在。如果你在景观中启动该应用会发生什么?在这种情况下,图像会显示吗?以横向模式启动也会导致灰色条。在景观工程的iPad模拟器中启动。与模拟器相比,设备上必须有一些根本不同的东西——但我在文档中找不到任何东西(除了文件名必须精确);确实绊倒了我的日志。现在我必须弄清楚为什么它是零。事实上,在旋转时,肖像图像也报告为零。我没有检查,这似乎太明显了。傲慢!已解决-将两个文件重命名为小写。作品那是我生命中的两个小时,我再也回不来了。非常感谢。
-(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];
}
}