Search code examples
iosxamarinxamarin.iosuinavigationcontrolleruinavigationbar

How to eliminate NavigationBar?


I'm new in Xamarin iOS development. I use NavigationController in my project. I want to hide a NavigationBar in a particular ViewController. Following code hides the bar, but doesn't eliminate the space.

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
        this.NavigationItem.LeftBarButtonItem = null;
        this.NavigationItem.HidesBackButton = true;
        this.NavigationController.ToolbarHidden = true;
    }

I want to eliminate the space as shown in the red broken frame. enter image description here


Solution

  • Set the NavigationBarHidden property to false:

    NavigationController.NavigationBarHidden = true;
    

    Or if you what to animate that, use the SetNavigationBarHidden method:

    Animate hide:

    NavigationController.SetNavigationBarHidden(true, true);
    

    Animate show:

    NavigationController.SetNavigationBarHidden(false, true);
    

    Re: iOS NavigationControllers