Swift: Tableview scrolls under navigation bar but over status bar?

≡放荡痞女 提交于 2019-12-24 01:15:50

问题


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:

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


回答1:


This will place the UITableView below the status bar.

self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;



回答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.




回答3:


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)


来源:https://stackoverflow.com/questions/41392421/swift-tableview-scrolls-under-navigation-bar-but-over-status-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!