2

I hid the navigation bar's shadow using the following trick:

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController?.navigationBar.shadowImage = UIImage()

I also have the following set:

    self.extendedLayoutIncludesOpaqueBars = true
    self.automaticallyAdjustsScrollViewInsets = true
    self.tabBarController?.tabBar.isHidden = true

Everything looks fine on my page, except that when I scroll up my tableView it goes under the navigation bar as expected, but above the status bar:

See tableView scrolling above status bar?

How do I make sure that the tableView scrolls under both the navigation bar and status bar?

leonardloo
  • 1,753
  • 3
  • 20
  • 31

4 Answers4

3

This will place the UITableView below the status bar.

self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;
Dupinder kaur
  • 188
  • 2
  • 12
2

You hid the default background of the navigation bar so this is to be expected. It means you are creating the green background in the navigation bar by yourself. You have to manually extend it to cover both status bar and navigation bar which is what the default background would do.

Or use a green image instead of a transparent one.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • Thanks!! This was the solution. It is to set the background image to green color! – leonardloo Dec 30 '16 at 08:48
  • This bothered me for a while. Setting Background image to nothing creates all kinds of weird behavior with jumpy views, black background and whatnot. Thank you. I used this to create image from color that matches the color I needed - https://stackoverflow.com/questions/6496441/creating-a-uiimage-from-a-uicolor-to-use-as-a-background-image-for-uibutton – Tomislav Markovski Sep 11 '18 at 15:05
0

I had same problem and the only thing which helped was to set a top anchor of my table view to safeArea topAnchor

tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
Pavel Bogart
  • 405
  • 5
  • 16
-1

You can try table view as under the UIEdgeInsetMake and also its scroll view

tableView.contentInset = UIEdgeInsetsMake(20.0, 0.0, 0.0, 0.0)
tableView.scrollIndicatorInsets = UIEdgeInsetsMake(20.0, 0.0, 0.0, 0.0)
Umesh Verma
  • 876
  • 7
  • 28
  • Thanks, but I tried that too and did not work. This only shifts the table view down, but when I scroll the table view up past the status bar the same thing happens. – leonardloo Dec 30 '16 at 07:57
  • your table scroll view is shift to top then try this **tableView.bounces = false** – Umesh Verma Dec 30 '16 at 08:06