美文网首页
UITableVIew刷新闪动乱跳的问题

UITableVIew刷新闪动乱跳的问题

作者: 北纬357 | 来源:发表于2019-08-17 21:17 被阅读0次

    Self-Sizing在iOS11下是默认开启的,Headers, footers, and cells都默认开启Self-Sizing,所有estimated 高度默认值从iOS11之前的 0 改变为UITableViewAutomaticDimension

    estimatedRowHeight这个属性是给tableView每行设置预估行高,如果目前项目中没有使用estimateRowHeight属性,在iOS11的环境下可以关闭Self-Sizing,因为开启Self-Sizing之后,tableView是使用estimateRowHeight属性的,这样就会造成contentSize和contentOffset值的变化,在估算行高机制下,contentSize的值是一点点地变化更新的,所有cell显示完后才是最终的contentSize值。因为不会缓存正确的行高,tableView reloadData的时候,会重新计算contentSize,就有可能会引起contentOffset的变化。

    解决代码:
     if #available(iOS 11.0, *){
          table_View.estimatedRowHeight = 0
          table_View.estimatedSectionFooterHeight = 0
          table_View.estimatedSectionHeaderHeight = 0
      }
            
    

    相关文章

      网友评论

          本文标题:UITableVIew刷新闪动乱跳的问题

          本文链接:https://www.haomeiwen.com/subject/dfzksctx.html