Weird uitableview behaviour in iOS11. Cells scroll up with navigation push animation

前端 未结 12 1432
粉色の甜心
粉色の甜心 2021-01-29 18:34

I have recently migrated some code to new iOS 11 beta 5 SDK.

I now get a very confusing behaviour from UITableView. The tableview itself is not that fancy. I have custo

相关标签:
12条回答
  • 2021-01-29 19:01

    I can reproduce the bug for iOS 11.1 but it seems that the bug is fixed since iOS 11.2. See http://openradar.appspot.com/34465226

    0 讨论(0)
  • 2021-01-29 19:01

    Also if you use tab bar, bottom content inset of the collection view will be zero. For this, put below code in viewDidAppear:

    if #available(iOS 11, *) {
        tableView.contentInset = self.collectionView.safeAreaInsets
    }
    
    0 讨论(0)
  • 2021-01-29 19:03

    You can edit this behavior at once throughout the application by using NSProxy in for example didFinishLaunchingWithOptions:

    if (@available(iOS 11.0, *)) {
          [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } 
    
    0 讨论(0)
  • 2021-01-29 19:07

    In my case this worked (put it in viewDidLoad):

    self.navigationController.navigationBar.translucent = YES;
    
    0 讨论(0)
  • 2021-01-29 19:08

    This is due to UIScrollView's (UITableView is a subclass of UIScrollview) new contentInsetAdjustmentBehavior property, which is set to .automatic by default.

    You can override this behavior with the following snippet in the viewDidLoad of any affected controllers:

        tableView.contentInsetAdjustmentBehavior = .never
    

    https://developer.apple.com/documentation/uikit/uiscrollview/2902261-contentinsetadjustmentbehavior

    0 讨论(0)
  • 2021-01-29 19:09

    Here's how I managed to fix this issue while still allowing iOS 11 to set insets automatically. I am using UITableViewController.

    • Select "Extend edges under top bars" and "Extend edges under opaque bars" in your view controller in storyboard (or programmatically). The safe area insets will prevent your view from going under the top bar.
    • Check the "Insets to Safe Area" button on your table view in your storyboard. (or tableView.insetsContentViewsToSafeArea = true) - This might not be necessary but it's what I did.
    • Set the content inset adjustment behavior to "Scrollable Axes" (or tableView.contentInsetAdjustmentBehavior = .scrollableAxes) - .always might also work but I did not test.

    One other thing to try if all else fails:

    Override viewSafeAreaInsetsDidChange UIViewController method to get the table view to force set the scroll view insets to the safe area insets. This is in conjunction with the 'Never' setting in Maggy's answer.

    - (void)viewSafeAreaInsetsDidChange {
        [super viewSafeAreaInsetsDidChange];
        self.tableView.contentInset = self.view.safeAreaInsets;
    }
    

    Note: self.tableView and self.view should be the same thing for UITableViewController

    0 讨论(0)
提交回复
热议问题