0
votes

I'm trying to add a UIView beneath the UINavigationBar in my UINavigationController. The view will serve as a placeholder for information messages (for example if we are having issues and content is not getting updated).

Adding the view it self and setting it's constraints is not an issue, but it is overlapping the content of the views that is contained in the navigation controller, which is not want I want. How can I set the content of the contained viewcontroller to respect the space which this new view takes up?

The screenshot is showing my custom (orange) view overlapping the content of the viewController that was pushed on to the navigation controller.

enter image description here

1
any update on my answer?Sahil
I'm not really sure your answer actually is what I need. I just need a static view above the content of what's pushed onto the navigation stack. No animation or anything. The question is about how to avoid the view overlapping the content.iCediCe

1 Answers

0
votes

Try Subclassing the UINavigationController and then add your orange view's height constraint to it. and call the function whenever you need it

import UIKit
class CustomNavigationController: UINavigationController{

    @IBOutlet weak var topViewHeight: NSLayoutConstraint!

    func animateHeight(height: CGFloat){
        UIView.animate(withDuration: 0.2) {
            self.viewControllers.forEach{ vc in
                let v = vc.view.frame
                vc.view?.frame = CGRect(x: 0, y: height, width: v.width, height: v.height)
            }
            self.topViewHeight.constant = height
        }
    }
}

how to use it? in your VC where you want to show/hide it:

(self.navigationController as? CustomNavigationController)?.animateHeight(height: 50)