ViewController covered up by NavigationBar

My view is going under the navigation bar. Most of the view is showing, except the top part which is covered up by the Nav bar. How do I prevent that?

2 answers

  • answered 2019-11-14 06:51 yeyuehan

    self.navigationController.navigationBar.isTranslucent = false

  • answered 2019-11-14 07:53 maniponken

    You must set the anchor to safeAreaLayoutGuide like this:

    myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)

    same thing for bottom if you have a tabbar:

    myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)

    Also, remember to set .translatesAutoresizingMaskIntoConstraints = false on "myView"