iOS 10 Beta 使导航栏按钮和标题在 pushViewController 上消失

iOS 10 Beta makes navigation bar buttons and title disappear on pushViewController

编辑:请在此处观看我的问题的视频: https://www.dropbox.com/sh/lzgs9mahx5mea13/AADLYfLQix7MDleDN1ER81qVa?dl=0

我在应用程序商店中有一个应用程序,它在 iOS 9.

上运行得非常好

但是在 iOS 10(在设备 iPhone 6s 上测试最新测试版),当主视图控制器上的单元格被选中并且详细视图是 "pushed" 时,我的导航栏的标题和导航栏按钮消失。

只有后退按钮可见。

即使我通过单击后退按钮或向后滑动返回到大师,他们也不会回来。弹出后,连 "master's" 标题和栏按钮都没有了。我不知道如何解决这个问题,因为没有错误。

在我的代码中,我没有将导航栏隐藏在任何地方,也没有对导航控制器做任何花哨的事情。

视图层次结构指导者的屏幕截图:

注意其他几个视图后面的标题和我的右栏按钮。后退按钮在最前面。这表明按钮和标题没有隐藏,它们被 3 个额外的视图覆盖:UIVisualEffectView、_UIVisualEffectBackdropView 和 _UIVIsualEffectFilterView

同样在视频中,您会注意到,如果我向后轻扫一半,然后取消轻扫,栏按钮就会返回。但是标题没有。

回到 master 后,注意 master 的导航栏内容被另外 2 个私有 class 视图覆盖:

我以编程方式推送到细节: 相关代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    PlaylistDetailViewController *pdvc = (PlaylistDetailViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"PlaylistDetailViewController"];
    pdvc.indexPath=indexPath;
    [self.navigationController pushViewController:pdvc animated:YES];
}

实际上,我一分钟前才想通。我正在使用来自 github.com/gklka/GKFadeNavigationController 的自定义 GKFadeNavigationController 删除它后,它解决了问题。

我 运行 遇到了同样的问题,但这是由于使用了添加模糊视图的自定义 UINavigationBar 引起的。 iOS10 似乎发生了一些变化,当向导航栏添加标题或按钮时,它们被添加到特定索引处,而不是被附加到子视图堆栈。

我能够通过覆盖方法 insertSubview:atIndex 并确保 blurView 始终插入子视图堆栈的后面来解决这个问题。

我为我的工作找到了孤独。使用符合导航栏的所有图像和颜色创建视图 (viewBackground),然后将其转换为图像并将其用作背景。

UIGraphicsBeginImageContextWithOptions(viewBackground.bounds.size, viewBackground.opaque, 0.0);
[viewBackground.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[[UINavigationBar appearance]            setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];

我遇到了和你现在面临的同样问题。我对我的代码及其工作做了一些更改。在我的viewWillAppear中写一段导航代码在dispatch_async

dispatch_async(dispatch_get_main_queue(), ^{
   //BACK BUTTON CALLING
   //NAVIGATION TITLE 
});
[super viewWillAppear:animated];

这将帮助您在 main queue 的帮助下设置标题和后退按钮。

如果您使用 LTNavigationBar 库 (https://github.com/ltebean/LTNavigationBar)

,同样的问题也会出现

我的解决方法是更改​​ UINavigationBar+Awesome.m:

中的代码
Replace
[[self.subviews firstObject] insertSubview:self.overlay atIndex:0];

with
[[self.subviews firstObject] insertSubview:self.overlay atIndex:self.subviews.count -1];

我也 运行 遇到这个问题,目前所有建议的解决方案都是:

  1. 太复杂
  2. 不起作用

最后我发现这是因为iOS10中更新了UINavigationBar的绘制周期造成的。

为了解决这个问题,我不得不用以下方法修复它:

self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBarHidden = NO;

基本上是触发导航栏重绘。

他们怎么能推出新版本的 OS 却破坏了这么重要的东西,这仍然很烦人。

Swift 3.0 解决方法:

子类 UINavigationBar 并覆盖 insertSubview(_ view: UIView, at index: Int)

    override func insertSubview(_ view: UIView, at index: Int) {
    if let _ = view as? UIVisualEffectView {
        super.insertSubview(view, at: 0)
    } else {
        super.insertSubview(view, at: self.subviews.count - 1)
    }
}