主视图控制器未在拆分视图控制器

时间:2017-03-12 18:13:23

标签: ios uisplitviewcontroller

在我的应用程序中,我在标签栏控制器中有一个拆分视图控制器,主视图控制器嵌入在导航控制器中。最初,详细视图控制器只是一个空白视图控制器。现在,当从1列分离到2时,主要位置的视图控制器奇怪地不再在顶部和底部条下方延伸。条形是半透明的,因此您应该能够在导航栏和标签栏中看到红色。我已将问题缩小到splitViewController(_:separateSecondaryFrom:),我将其用于在导航控制器中嵌入细节。我不明白为什么这会导致主要的这种行为。我执行此方法的不正确之处是什么?

在折叠界面中按预期显示在条形图中的红色: enter image description here

扩展到两列后,条形图中不再出现红色: enter image description 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()
    }

    return UINavigationController(rootViewController: detailController)
}

I've uploaded a sample project here.

1 个答案:

答案 0 :(得分:0)

在绘制酒吧下面的视图的半透明度和模糊时,可能会出现打嗝。可能是由于框架中的一些绘图和缓存优化,但当我在导航栏上触发隐藏栏和显示事件时,它很好。

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
}

让我知道它是否适合你。