1.UITableView的在iOS11上的侧滑删除问题
使用一下方法实现侧滑删除时,在iOS11以前的系统无问题。在iOS上,出现删除错乱或卡顿现象。
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
//
}
解决:
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
tableView.setEditing(false, animated: true)
let deleteAction = UIContextualAction.init(style: .destructive, title: "删除") { (action, view, completionHandler) in
//
}
let actions = UISwipeActionsConfiguration(actions: [deleteAction])
return actions
}
2.MJRefresh iOS11适配
使用MJRefresh时,在UITableView中使用beginRefreshing实现下拉刷新时,页面无法滚动到顶部。
使用UICollectionView不会出现此现象。
解决方法:
if #available(iOS 11.0, *) {
tableView.estimatedRowHeight = 0;
}
3.UITableView:默认开启Self-Sizing
在iOS11下Headers, footers, and cells都默认开启Self-Sizing。如果目前项目中没有使用estimateRowHeight属性,在iOS11的环境下就要注意了,因为开启Self-Sizing之后,tableView是使用estimateRowHeight属性的,这样就会造成contentSize和contentOffset值的变化,如果是有动画是观察这两个属性的变化进行的,就会造成动画的异常。
因为在估算行高机制下,contentSize的值是一点点地变化更新的,所有cell显示完后才是最终的contentSize值。因为不会缓存正确的行高,tableView reloadData的时候,会重新计算contentSize,就有可能会引起contentOffset的变化。iOS11下不想使用Self-Sizing的话,可以通过以下方式关闭:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;