Swift: Tableview scrolls under navigation bar but

2019-07-14 02:21发布

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?

3条回答
\"骚年 ilove
2楼-- · 2019-07-14 02:38

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.

查看更多
Deceive 欺骗
3楼-- · 2019-07-14 02:54

This will place the UITableView below the status bar.

self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;
查看更多
一纸荒年 Trace。
4楼-- · 2019-07-14 02:55

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)
查看更多
登录 后发表回答