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条回答
聊天终结者
2楼-- · 2019-04-10 06:00

You can use a separate class for changing color, make the background color that class , your desired color, and then use that class as class of your rootViewController. I did, it works.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-04-10 06:02

Filed a bug report about this weeks ago and Apple said that this is a known bug of 4.2. I then asked if there was a way to fix this, but no reply so far.

It's also no use replacing the UINavigationbar with a subclassed/customized navigation bar. The popover seems to perform some secret nasty stuff on the UINavigatioBar which kills the tintColor and won't allow to reset it (it'll always remain 'nil', even after resetting it).

I basically gave up and told the customer he'll have to live with it until the next update is out (hopefully).

查看更多
We Are One
4楼-- · 2019-04-10 06:02

Cool, fixed it.

Added to my RootViewController where the splitviewcontroller and nav bar is declared:

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:YES];


    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

}
查看更多
We Are One
5楼-- · 2019-04-10 06:03

for Steve (detect PoPView or splitView navigationBar of RootViewControll) [splitview IPAD]

Yuo have to create a class method (setLand:int i) on RootViewController called from detailviewcontroller in these method:

- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    // LANDSCAPE !!!!
    [RootViewController setLand:1];

and

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
    // PORTRAIT!!
    [RootViewController setLand:0];

and on RootViewController:

    static int landscape=2;

    ...

// SetMethod for class variable landscape   
        + (void)setLand:(int)i 
        {
            if(landscape!=i){
                landscape = i;

            }
        }

and finaly alway in RootViewController

 - (void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
     if(landscape == 1)
     {
       //LANDSCAPE!
       CUSTOM FOR LANDSCAPE
       self.navigationController.navigationBar.barStyle =...
     }
     else if(landscape == 0)
     {
       //PORTRAIT!
       CUSTOM FOR PORTRAIT
       self.navigationController.navigationBar.barStyle =...
     }
   }

..this works well in my app, editing custom landscape/portrait navigationBar

查看更多
我想做一个坏孩纸
6楼-- · 2019-04-10 06:04

There seems to be an issue with 4.2 and setting the tintColor of the navigationBar after rotation. You can set the barStyle correctly using the answers above, but not the tintColor. Anybody else having the same issue?

查看更多
叛逆
7楼-- · 2019-04-10 06:08

This problem is fixed used the following code

@implementation ChangeNavigationBarColor

- (void) setTintColor:(UIColor*)color
{
    [super setTintColor:[[BrandingManager sharedBrandingManager] tintColorForNavigationController]];
}


@interface ChangeNavigationBarColor : UINavigationBar {

}

@end
查看更多
登录 后发表回答