video of the tableview animation bug
我有一个可扩展/折叠其单元格的表格视图。
从iOS 11开始,tableView在插入和删除行时开始表现异常。contentSize在动画块发生之前已更改,因此,在视频中,您可以看到折叠的单元格上发生了错误的滚动回退。动画看起来不对。
此代码在iOS 10上运行良好。有人知道苹果方面发生了什么变化吗?这是一个已知的问题?
public func insertingRowsForAccordion(_ indexArray: [IndexPath], selectedRowIndex: Int) {
beginUpdates()
insertRows(at: indexArray, with: UITableViewRowAnimation.fade)
endUpdates()
// Scroll to selection after expanding children
scrollToRow(at: IndexPath(row: selectedRowIndex, section: 0), at: UITableViewScrollPosition.top, animated: true)
}
public func removeRowsForAccordion(_ indexArray: [IndexPath]) {
beginUpdates()
deleteRows(at: indexArray, with: UITableViewRowAnimation.fade)
endUpdates()
}
我在iOS 11 UITableView
上遇到了无数问题。转到整个应用程序中的每个UITableView
并执行以下操作解决了我所有的问题。
将estimatedRowHeight
,estimatedSectionHeaderHeight
和estimatedSectionFooterHeight
设置为0。
我在iOS 11上删除表格行动画时遇到类似的问题,有时会奇怪地滚动表格单元格(iOS 10正常工作)。帮助实现该委托方法返回行高的原因是:
- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
之后,iOS 10和11都可以正常工作。
在iOS 11.2中,使用标准的行操作删除一行后,动画效果很差。我只能通过在CATransaction中包装行删除和行操作消除来改善这种情况。
我先取消行操作,然后等待该动画完成,然后再从表格视图中删除行。
它至少不再绕过表格视图内容偏移了,而是一个漫长的两步动画。我仍在寻找更好的解决方案。
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()
我使用此代码修复了它:
self.tableView.beginUpdates()
// ...
self.tableView.endUpdates()
self.tableView.layer.removeAllAnimations()
对我有用的部分修补程序正在设置estimatedRowHeight
大量。
tableView.estimatedRowHeight = 1000