主视图控制器未在拆分视图控制器中的 top/bottom 栏下扩展

Primary view controller not extending under top/bottom bars in split view controller

在我的应用程序中,我在选项卡栏控制器中有一个拆分视图控制器,主视图控制器嵌入在导航控制器中。最初,细节视图控制器只是一个空白视图控制器。现在,从 1 列分离到 2 列后,位于主要位置的视图控制器奇怪地不再扩展到顶部和底部栏下方。这些栏是半透明的,因此您应该能够在导航栏和选项卡栏中看到红色。我已将问题缩小到 splitViewController(_:separateSecondaryFrom:),我用它来将详细信息嵌入到导航控制器中。不过,我不明白为什么这会导致主节点出现这种行为。我执行此方法有什么不正确的地方?

在折叠界面中,红色按预期出现在条形图中:

扩展到两列后,红色不再出现在条形图中:

func splitViewController(_ splitViewController: UISplitViewController, separateSecondaryFrom primaryViewController: UIViewController) -> UIViewController? {
    //in the case where it's separating into two, we want to embed the detail in a navigation controller
    let primaryNavController = primaryViewController as! UINavigationController

    let detailController: UIViewController
    if primaryNavController.viewControllers.count > 1 {
        detailController = primaryNavController.viewControllers[1]
    } else {
        detailController = ViewController()
    }

    return UINavigationController(rootViewController: detailController)
}

I've uploaded a sample project here.

在绘制条形图下方视图的半透明和模糊时可能会出现问题。可能是由于框架中的一些绘图和缓存优化,但是当我在导航栏上触发隐藏栏和显示事件时,没问题。

func splitViewController(_ splitViewController: UISplitViewController, separateSecondaryFrom primaryViewController: UIViewController) -> UIViewController? {
    //in the case where it's separating into two, we want to embed the detail in a navigation controller
    let primaryNavController = primaryViewController as! UINavigationController

    let detailController: UIViewController
    if primaryNavController.viewControllers.count > 1 {
        detailController = primaryNavController.viewControllers[1]
    } else {
        detailController = ViewController()
    }
    //Fake trigger to force bars to draw blur translucency
    let navigationNew = UINavigationController(rootViewController: detailController)
    navigationNew.setNavigationBarHidden(true, animated: false)
    navigationNew.setNavigationBarHidden(false, animated: false)
    return navigationNew
}

让我知道它是否适合你。