How to keep navigation bar from disappearing with MSMessagesViewController -> UIContainerView -> UINavigationController -> UITableViewController?

倖福魔咒の 提交于 2019-12-24 05:49:58

问题


I am trying to put a navigation controller with a table view controller within an iMessage app (iOS 10). This seems to work when I put the UINavigationController within an UIContainerView within the MSMessagesViewController.

However, this breaks when in expanded view. The UINavigationBar that the controller has disappears.

How can I remedy this, or am I taking the wrong approach?


回答1:


Let me start with the assumption that you used view.addSubview to add your UITableViewController to the MSMessagesAppViewController

In order to show the navigation bar correctly. Make sure you have set all your constraints correctly. Here's the example I have, and hopefully this would work for you:


    // Embed the new controller. Recommended way of presenting VC shown in WWDC (icecream example). Ugly but does the work
    addChildViewController(controller)

    view.addSubview(controller.view)
    let viewRect = view.bounds
    controller.view.frame = viewRect
    controller.view.translatesAutoresizingMaskIntoConstraints = false


    controller.view.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    controller.view.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    controller.view.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true

    if presentationStyle == .compact {
        controller.view.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    } else {
        controller.view.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true
    }

    controller.didMove(toParentViewController: self)

Here's the link to the post on the Apple Developer Forum which solved my problem: https://forums.developer.apple.com/thread/52049




回答2:


In the screens you show there isn't any problem with the navigation bar!!




回答3:


So in my case, I was using Storyboards, so I will add in the Storyboard solution to this.

Similar to DLee's answer, the top constraint needs to be set to the "Top Layout Guide" not "Top." Here's what it looks like in a Storyboard:

In my case, I used a Container View to hold everything, so with this having the top layout guide set as the top constraint, it made everything go in the right place.

In my post, I originally used the "Top" which was what caused parts of the iMessage app (specifically the navigation bar) to disappear.



来源:https://stackoverflow.com/questions/38426146/how-to-keep-navigation-bar-from-disappearing-with-msmessagesviewcontroller-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!