Any idea how to shift the navbar view so I have the expected padding? It looks like the popover frame is overlapped on the nav bar's top, left and right side.
This is my nav controller in a popover controller derived from the app's root splitViewController. It's an issue on < iOS 5.1
The solution is to remove the custom UINavigationBar
styling when in a UIPopoverController
. I'll post the implementation when it's ready.
Update
So this is a funny one. iOS 4.x and iOS 5.0 use a real, genuine popover, that is the floating popover. Custom navigation bars don't work in this popover (navBar setBackgroundImage
in iOS 5.0 and the category drawRect
override in iOS 4.x).
However, 5.1 uses more of a "slideover," where the custom navbar works nicely. It's a much cleaner design actually.
Anyway, my point is that now I need to remove the custom navBar formatting only when in portrait AND the OS is less than 5.1. Normally, you'd want to use respondsToSelector
in lieu of manually figuring out an OS version. That doesn't work in this case.
Still working on the iOS 4.x fix, but here's iOS 5.0:
In my appDelete
, where I set up the custom navBar:
//iOS 5.x:
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
UIImage *image = [UIImage imageNamed:@"header.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
//iOS 4.x:
@implementation UINavigationBar (CustomBackground)
- (void)drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed:@"header.png"];
[image drawInRect:CGRectMake(0, 0, 320, 44)];
}
@end
I set up an observer in didFinishLaunching
:
//start orientation notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
- (void) didRotate:(NSNotification *)notification
{
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version < 5.1)
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationIsPortrait(orientation))
{
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
}
else
{
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
UIImage *image = [UIImage imageNamed:@"header.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
}
}
}