A black bar appears below the navigation bar.

There are several similar questions that did not receive answers, but were vaguely described. I reduced the problem to a very thin application and added detailed screenshots. I would really appreciate a solution to this!

The only code involved is one line added to the root VC's viewDidLoad . The purpose of this line is to make an opaque navigation controller:

- (void)viewDidLoad { [super viewDidLoad]; self.navigationController.navigationBar.translucent = NO; } 

Critical information for this question is that "Title1" has an invitation in its navigation element , while "Title2" does not request .

I have a storyboard with one navigation controller, one VC root called "Title1", with a segue button that goes to the second VC called "Title2"

storyboard


When you click a button here:

pre press


I get this strange screen:

after press


When you press back (Title1), it gets worse (i.e. the original label Title1 has been advanced and is now no longer visible !!!):

after back

Anyone?

+7
ios ios7
source share
4 answers

Late answer, but I stumbled upon this problem today and found your question and it does not yet have an accepted answer.

I got this error by switching from the viewController prompt to the invited viewController in the storyboard.

I got this black bar, just like you.

And fix:

 // In prompted vc override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { UIView.setAnimationsEnabled(false) self.navigationItem.prompt = nil UIView.setAnimationsEnabled(true) } 

This will immediately remove the request before switching the view manager.

UPDATE

 func prompt() -> String? { return nil } override func viewWillAppear(animated: Bool) { let action = { self.navigationItem.prompt = self.prompt() } if self.navigationController?.viewControllers.count <= 1 { UIView.performWithoutAnimation(action) } else { action() } } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { UIView.performWithoutAnimation { self.navigationItem.prompt = (segue.destinationViewController as? ViewController)?.prompt() } } 
+2
source share

It appears that the translucent UINavigationBar property has been confused with other view controllers.

I would recommend the following approach.

Create a base view controller from which other inheriting controllers inherit as follows:

 #import "BaseViewController.h" @interface BaseViewController () @end @implementation BaseViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationController.navigationBar.translucent = NO; } 

other view controllers inherit above BaseViewController

//interface

 #import <UIKit/UIKit.h> #import "BaseViewController.h" @interface ViewController : BaseViewController @end 

// implementation

 #import "ViewController.h" @implementation ViewController - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // Here translucent property is enabled when the view is about to be disappeared. // However note that, translucent property needs to be enabled only on those view controllers which has prompt set on their navigation items. self.navigationController.navigationBar.translucent = YES; } 

Other view controllers without a fast implementation will work as usual, but they must also inherit from BaseViewController.

+3
source share

It seems that Xcode has some problems when changing the height of the navigationBar, since the view of the main controller doesn't change accordingly.

I found a solution for this, not sure if this is the best ... but it works.

Just inherit the viewWillAppear and viewWillDisappear in your first view controller (the one with the hint):

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationItem.prompt = @"Prompt1"; [UIView animateWithDuration:UINavigationControllerHideShowBarDuration delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ [self.view setFrame:CGRectMake(0, 94, 320, 386)]; } completion:^(BOOL finished){ }]; } - (void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // Sets prompt to nil self.navigationItem.prompt = nil; [UIView animateWithDuration:UINavigationControllerHideShowBarDuration delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ [self.view setFrame:CGRectMake(0, 64, 320, 416)]; } completion:^(BOOL finished){ }]; } 

I did not focus on frame size (3.5 inches for iPhone). You must calculate this size, or you may have problems with large screens.

+1
source share

The best way to solve this problem is to set the window background during push ie,

 let appdelegate = UIApplication.shared.delegate as! AppDelegate appdelegate.window?.backgroundColor = UIColor.white 
0
source share

All Articles