导航栏下方会出现黑条

问题描述:

有几个类似的问题没有得到答案,但含糊地描述。我已将问题缩减为非常薄的应用程序,并添加了详细的屏幕截图。我非常感谢这个解决方案!

There are several similar questions which got no answers but were describe vaguely. I have reduced the problem into a very thin application, and added detailed screenshots. I would highly appreciate a solution for this!

唯一涉及的代码是一行添加到根VC的viewDidLoad 。这一行的目的是使导航控制器不透明:

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

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

此问题的一个重要信息是'Title1'有一个提示在其导航项中,而'Title2'没有提示

A critical information for this question is that 'Title1' has a prompt in its navigation item, while 'Title2' has not prompt.

我有一个带有一个导航控制器的故事板,一个root VC称为Title1,带有一个segue按钮,该按钮带到第二个名为Title2的VC

I have a storyboard with one navigation controller, one root VC called "Title1", with a segue button which takes to a second VC called "Title2"

按此处按钮时:

我收到了这个奇怪的屏幕:

I'm getting this strange screen:

按下后(Title1),它会得到更糟糕的是(即:标题1的原始标签被推高,现在不再被看见!!!):

When pressing back (Title1), it gets worse (i.e.: the original label of Title1 was pushed up and now not being seen anymore!!!):

任何人都可以吗?

迟到的答案我偶然发现了这个今天的问题,发现你的问题,但它还没有接受答案。

Late answer but I stumbled across this problem today and found your question and it doesn't have an accepted answer yet.

我从故事板中的提示viewController转到非提示的viewController时出现此错误。

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.

并修复:

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

这将在切换viewcontroller之前立即删除提示。

This will remove the prompt instantly before switching viewcontroller.

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()
    }
}