UISearchBar on UITableView strange offset issue

前端 未结 4 1880
情书的邮戳
情书的邮戳 2021-01-02 06:10

I have a UITableView which has a UISearchBar subview. This is all on the view of a UIViewController along with a few other subviews (l

4条回答
  •  心在旅途
    2021-01-02 06:33

    This happens because a UIViewController's property called automaticallyAdjustsScrollViewInsets

    With iOS 7, UIViewControllers have a property called automaticallyAdjustsScrollViewInsets, and it defaults to YES. If you have a scroll view that is either the root view of your view controller (such as with a UITableViewController) or the subview at index 0, then that property will adjust both the contentInset and the scrollIndicatorInsets. This will allow your scroll view to start its content and scroll indicators below the navigation bar (if your view controller is in a navigation controller).

    From Big Nerd Ranch

    If you are using storyboards, you can change it by selecting the view controller and in the attributes inspector deselect Adjust scroll view insets.

    Here is its description from apple documentation:

    Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.

提交回复
热议问题