iOS 11 UITableView delete rows animation bug

前端 未结 5 1213
情话喂你
情话喂你 2020-12-05 10:20

video of the tableview animation bug

I have a table view which expands/collapse its cells.

As of iOS 11, the tableView starts to behave strangely on insertio

相关标签:
5条回答
  • I have been having countless problems with iOS 11 UITableView. Going to every UITableView in my entire app and doing the following fixed all of my problems.

    Set estimatedRowHeight, estimatedSectionHeaderHeight, and estimatedSectionFooterHeight to 0.

    Source: iOS 11 Floating TableView Header

    0 讨论(0)
  • 2020-12-05 11:05

    A partial fix that is working for me is setting estimatedRowHeight to a large number.

    tableView.estimatedRowHeight = 1000
    
    0 讨论(0)
  • 2020-12-05 11:07

    In iOS 11.2, I had a bad animation after deleting a row using the standard row actions. I was only able to improve the situation by wrapping the row delete and row action dismissal in a CATransaction.

    I dismiss the row actions first and wait for that animation to complete before deleting the row from the table view.

    It at least doesn't jump around the table views content offset anymore, but is a lengthy two step animation. I'm still looking for a better solution.

            CATransaction.begin()
            CATransaction.setCompletionBlock({
                self.tableView.beginUpdates()
                self.myViewModel?.items?.remove(at: indexPath.row)
                self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.top)
                self.tableView.endUpdates()
            })
            self.tableView.setEditing(false, animated: true)
            CATransaction.commit()
    
    0 讨论(0)
  • 2020-12-05 11:13

    I fixed it by using this code:

    self.tableView.beginUpdates()
    // ...
    self.tableView.endUpdates()
    self.tableView.layer.removeAllAnimations()
    
    0 讨论(0)
  • 2020-12-05 11:15

    I had similar problem with table row removal animation on iOS 11 sometimes scrolling the table cells strangely (iOS 10 worked just fine). What helped was implementing this delegate method returning row height:

    - (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath

    After that both iOS 10 and 11 work just fine.

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