Black bar appears under navigation bar
It appeared as translucent property of UINavigationBar appeared to be messed up with frame other view controllers.
I would recommend following approach.
Create a base view controller from which other view controllers will inherit as follows,
#import "BaseViewController.h"
@interface BaseViewController ()
@end
@implementation BaseViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
}
other view controllers will 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 prompt implementation will work as usual however they also needs to inherit from BaseViewController.
Late answer but I stumbled across this problem today and found your question and it doesn't have an accepted answer yet.
I got this error while going from a prompted viewController to a non prompted viewController in storyboard.
I got that black bar just like you.
And to fix:
// In prompted vc
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
UIView.setAnimationsEnabled(false)
self.navigationItem.prompt = nil
UIView.setAnimationsEnabled(true)
}
This will remove the prompt instantly before switching viewcontroller.
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()
}
}
The best way to solve this issue is setting the background of the window during push i.e,
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.window?.backgroundColor = UIColor.white