zoukankan      html  css  js  c++  java
  • ios开发之--MJRefresh上拉加载的时候,tableview会向上偏移

    1,出现这种情况的原因:

    这个应该是UITableView最大的改变。我们知道在iOS8引入Self-Sizing之后,我们可以通过实现estimatedRowHeight相关的属性来展示动态的内容,实现了estimatedRowHeight属性后,得到的初始contenSize是个估算值,是通过estimatedRowHeight乘以 cell的个数得到的,并不是最终的contenSize,只是当前屏幕能够显示的cell个数,滑动时,tableView不停地得到新的cell,更新自己的contenSize。

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

      如果目前项目中没有使用estimateRowHeight属性,在iOS11的环境下就要注意了,因为开启Self-Sizing之后,tableView是使用estimateRowHeight属性的,这样就会造成contentSize和contentOffset值的变化,如果是有动画是观察这两个属性的变化进行的,就会造成动画的异常,因为在估算行高机制下,contentSize的值是一点点地变化更新的,所有cell显示完后才是最终的contentSize值。因为不会缓存正确的行高,tableView reloadData的时候,会重新计算contentSize,就有可能会引起contentOffset的变化。

    2,解决方案,代码如下:

    -(void)creatUI
    {
        communTableV = [[UITableView alloc]initWithFrame:CGRectMake(0, NavHeight, KscreenW, KscreenH-NavHeight-bottomHeight-50) style:UITableViewStylePlain];
        communTableV.delegate = self;
        communTableV.dataSource = self;
        communTableV.tableFooterView = [[UIView alloc]init];
        communTableV.tableHeaderView = [self thirdV];
        communTableV.estimatedRowHeight = 0;
        
        communTableV.estimatedSectionFooterHeight = 0;
        
        communTableV.estimatedSectionHeaderHeight=0;
        if (@available(iOS 11.0, *)) {
            communTableV.contentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentNever;
        } else {
            // Fallback on earlier versions
        }if (@available(iOS 11.0, *)) {
            communTableV.contentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentNever;
        } else {
            // Fallback on earlier versions
        }
        
        [self.view addSubview:communTableV];
    }

    仅做记录,别问我为什么下面的判断了两次,是警告点出来的!

  • 相关阅读:
    angular中transclude的理解
    node express中使用static的错误
    待研究———node中使用session时的id不断更改问题
    node 中mongoose使用validate和密码加密的问题
    exports 和 module.exports 的区别
    node.js开发错误——DeprecationWarning: Mongoose: mpromise
    Mongoose全面理解
    【js】JSON.stringify 语法实例讲解
    springboot+mybatis使用PageHelper分页
    连接mysql提示Establishing SSL connection without server's identity verification is not recommended错误
  • 原文地址:https://www.cnblogs.com/hero11223/p/9157291.html
Copyright © 2011-2022 走看看