IPad SplitView changes the color of the main navigation bar

A strange problem: after turning my application to a portrait, selecting a toolbar item and setting the uipopovercontroller if I turn back to the landscape, the UINavigationController on the right side (objectAtIndex: 0 from SplitView) changes the color of the navigation bar, I donโ€™t know why. I set the value of barStyle = UIBarStyleBlackOpaque in Interface Builder;

After returning to landscape mode, it becomes silver.

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

Does anyone have an idea?

+4
source share
9 answers

viewDidLoad will only be called the first time you view your view (or if it has been cleared due to memory problems). Try reinstalling barStyle in your WillAppear view or even splitViewController: willShowViewController: invalidatingBarButtonItem :.

+7
source

for Steve (PoPView detection or splitView navigationBar RootViewControll) [splitview iPad]

Yuo must create a class method (setLand: int i) in the RootViewController, called from detailviewcontroller in this 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 the RootViewController:

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

and finally 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 application, editing custom landscape / portrait navigation

+2
source

There seems to be a problem with 4.2 and installing the tintColor navigation bar after rotation. You can set barStyle correctly using the answers above, but not tintColor. Does anyone else have the same problem?

+2
source

@Brendan G. Lim and any other tintColor related issues finally got it working with a custom navigation bar:

  • Create a custom navigation file by subclassing from UINavigationBar
 @interface CustomNavigationBar : UINavigationBar { } @end 
  • In your implementation file, override the setTintColor method
 @implementation CustomNavigationBar -(void)setTintColor:(UIColor *)tintColor { [super setTintColor :[self tintColor]]; } @end 
  • Open MainWindow.xib and select the navigation bar on which you want to set the color. In the [Apple] [4] Identity area, select CustomNavigationBar as the class.

  • In the [Apple] [1] attribute area, set the panel color.

What is it!

+2
source

Cool, fixed it.

Added to my RootViewController, where the splitviewcontroller and nav bar controller are declared:

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; } 
+1
source

I have the same problem, but resetting barStyle in viewWillAppear causes another problem. Installing it there also installs it when it is displayed in a popover, so it no longer matches the color of the popover. How to set barStyle to what I want only when it is displayed in the left pane of the split view controller? I think I could set it to look, it will appear only when the orientation is landscape, but it seems dirty. Also, setting it to 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 mistake on the apple side. He should change it back to the style that it was originally, and not by default.

+1
source

This problem is fixed used the following code

 @implementation ChangeNavigationBarColor - (void) setTintColor:(UIColor*)color { [super setTintColor:[[BrandingManager sharedBrandingManager] tintColorForNavigationController]]; } @interface ChangeNavigationBarColor : UINavigationBar { } @end 
+1
source

Published a bug report about this a week ago, and Apple said it was a known bug in 4.2. Then I asked if there is a way to fix this, but there is no answer yet.

Also, there is no need to replace the UINavigationbar with a subclass / custom navigation bar. The popover seems to do some secret nasty stuff on the UINavigatioBar, which kills tintColor and will not let it reset (it will always remain โ€œzeroโ€, even after resetting it).

In principle, I refused and told the client that he would have to live with him until the next update (I hope).

+1
source

You can use a separate class to change the color, make the background color of this class the desired color, and then use this class as the class of your root controller. I did, it works.

0
source

Source: https://habr.com/ru/post/1306988/


All Articles