remy boys
remy boys

Reputation: 2948

hide NavigationBar without lifting up the View

hiding my NavigationBar with this :

func hideAndShow(){

   if self.navigationController?.navigationBar.hidden == true {
        self.navigationController?.setNavigationBarHidden(false, animated: true)

    }else {
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }
 }

but its also lifting up my View (maybe because View is below the Navigation), how can i hide it without lifting up my View

see the below image for better understanding

image

as you can see that my image in my view also get shifted up while hiding the NavigationBar any idea how can i fix this ??

can we just show the view below the layer of navigation bar ???

Upvotes: 0

Views: 83

Answers (1)

Apfelsaft
Apfelsaft

Reputation: 5846

Two steps are required to solve your problem:

  1. Add self.edgesForExtendedLayout = UIRectEdge.All to viewWillAppear. As a result your view will start at the top of the screen instead of below the NavigationBar. You can read more about edgesForExtendedLayout here: https://stackoverflow.com/a/19585104/1447641

  2. Add a top constraint of {navigationbarheight} to your ImageView.

After that the position of the ImageView shouldn't be effected by the NavigationBar anymore.

Upvotes: 1

Related Questions