TableView scroll underlying top bar

半世苍凉 提交于 2019-12-10 23:15:34

问题


Since I updated my app to iOS 7 new GUI I have a problem that I can't solve.

My app consists in a scrollable TableView. Trouble is that TableView scrolls underlying top bar, means that table doesn't consider top bar and extends till the top and it's ugly to see.

I tried removing check on "Extend edges under Top Bars" but it's the same.

How can I solve this?


回答1:


One solution is: set the table view's contentInset and scrollIndicatorInsets to have a top inset of 20. The table view will still underlap the status bar, but it will be completely visible when scrolled all the way.

If you don't like that solution, and you want a permanent empty area behind the status bar, you will have to change the way you pin/position the top of the table view, to allow for the status bar. How you do this depends on whether you are using auto layout. If you are, just pin to the top layout guide. If you are not, you will have to use the "delta" field provided in the nib editor.

If you are using a UITableViewController, however, you are not in charge of the top of the table view; it is a full-screen view and it is the view controller's main view. This is quite a troublesome situation, actually. I have resorted to two solutions:

  • Put the whole thing into a UINavigationController in order to get the nav bar to "run interference" for me.

  • Or, embed the table view controller in a custom parent view controller just so that I can position the top of the table view.




回答2:


In UINavigationController I created an UIView, which goes under status bar but in front of embed controller (the Table), so table disappear behind this view and status bar is always on top.

var patch: UIView!

override func viewDidLoad() {
    super.viewDidLoad()

    patch = UIView(frame: CGRectMake(0, 0, view.bounds.width, 20))
    patch.backgroundColor = UIColor.redColor()
    self.view.addSubview(patch)
}

Then I make it disappear when screen goes in Landscape (in iOS9, status bar automatically disappear in Landscape) and make it reappear when screen goes in Portrait.

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        patch.hidden = true
    } else {
        patch.hidden = false
    }
}


来源:https://stackoverflow.com/questions/33187856/tableview-scroll-underlying-top-bar

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