I have an app which starts with a root UINavigationController. This controller then pushes and pops various other UIViewControllers – that all works fine.
My app has a custom graphic for the navigationController.navigationBar.backgroundImage. There is one image for the iPhone platform. There are two images for the iPad platform – one for portrait, one for landscape. The iPad is the platform of issue as it rotates, the iPhone platform is portrait only.
I had already written code in -(void)willRotateToInterfaceOrientation: to detect the rotation, and set the navigationBar.backgroundImage to the correct orientation graphic, if the platform is iPad.
In the iPad 5.0 simulator – it works fine; rotating the iPad on screen results in the correct navigationBar graphic regardless of orientation.
On the device – it doesn’t work – The graphic appears correctly on iPad device launch in portrait. When I rotate to landscape, the navigationBar changes to a standard grey one. When I rotate back the grey ‘sticks’.
I have tried calling setNeedsDisplay – no change.
I have tried setting navigationBar.tintColor = [UIColor clearColor] – no change.
I have checked the filenames of the graphics in the code are identical to the actual filenames – they are.
Code for rotation:
-(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];
}
}
}
Check whether
titleImageis nil. I have a feeling that your image paths are not correct, or those images are not correctly copied to iPad.