iPad SplitView changes main navigation bar color

2019-04-10 05:38发布

Weird problem: After rotating my app to portrait, picking the toolbar item and exposing the uipopovercontroller, if I rotate back to landscape, the UINavigationController on the right side (objectAtIndex:0 of the SplitView) changes the color of the navigation bar. I am not sure why. I have it set in Interface Builder to be barStyle = UIBarStyleBlackOpaque;

It turns silver after it returns to landscape mode.

This only happens if I rotate it to portrait, create the popover, and select something in the navigation controller, which pushes another tableViewController. Even setting the properties in the viewDidLoad method does nothing.

Anyone have an idea?

9条回答
The star\"
2楼-- · 2019-04-10 06:10

viewDidLoad will only get called the first time your view is displayed (or if it's cleared due to memory issues). Try re-setting the barStyle in your viewWillAppear, or even – splitViewController:willShowViewController:invalidatingBarButtonItem:.

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-10 06:17

I'm having this same problem but resetting the barStyle in viewWillAppear causes another problem. Setting it there also sets it when it is shown in the popover, so it no longer matches the popover color. How can I set the barStyle to what I want only when it is being shown in the left pane of the split view controller? I guess I could set it in view will appear only when the orientation is landscape but that seems dirty. Also, setting it in splitViewController:willShowViewController:invalidatingBarButtonItem: does not work at all since I think this is called before the split view controller sets the styles back to default. This seems like a really stupid bug on apple's part. It should be changing it back to the style it originally was, not the default one.

查看更多
小情绪 Triste *
4楼-- · 2019-04-10 06:24

@Brendan G. Lim and any others having trouble with the tintColor, finally got it working with a custom navigation bar:

  1. Create a custom navigation file subclassed from UINavigationBar
@interface CustomNavigationBar : UINavigationBar 
{
}

@end
  1. In your implementation file, override the setTintColor method
@implementation CustomNavigationBar

-(void)setTintColor:(UIColor *)tintColor
{
  [super setTintColor :[self tintColor]];
}

@end
  1. Open MainWindow.xib, and select your navigation bar you want to set the color to. In your Identity pane [Apple][4] select CustomNavigationBar as the class.

  2. In the attributes pane [Apple][1] set the color of the bar.

That's it!

查看更多
登录 后发表回答