zoukankan      html  css  js  c++  java
  • tableview的header和footer取消悬停或者是粘滞

    tableview的header和footer取消悬停或者是粘滞,网上找的有效方法是用

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView  {  
        if (scrollView.tag == 100102) {  
            UITableView *tableview = (UITableView *)scrollView;  
            CGFloat sectionHeaderHeight = 20;  
            CGFloat sectionFooterHeight = 20;  
            CGFloat offsetY = tableview.contentOffset.y;  
            if (offsetY >= 0 && offsetY <= sectionHeaderHeight) {  
                tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);  
            }else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight) {  
                tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);  
            }else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height) {  
                tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);  
            }  
        }  
    } 

    但有个问题,若有下拉刷新,那么整个tableview的样式会发生改变。因为下拉刷新也是靠contentInset设置。
    简单的方法是设置tableview的style为UITableViewStyleGrouped。这样接解决了悬浮问题。但又会引发新问题,默认下section之间的间距很大,仅仅单独设置header或footer的高度是不行的。显示效果的各个section间距其实是section头部和底部的组合。所以得组合设置才有效果

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
        return 0.01f;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)];
        view.backgroundColor = [UIColor clearColor];
        return view;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
        return 10;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)];
        view.backgroundColor = [UIColor clearColor];
        return view;
    }
  • 相关阅读:
    解决chrome浏览器无法得到window.showModalDialog返回值的问题
    Javascript 中 null、NaN和undefined的区别
    Windows Server 2003 asp网页不能访问的常见问题
    关于SQLServer无法对数据库'XXX'执行删除,因为它正用于复制。错误:'3724' 的解决方案
    关于Gridview激发了未处理的事件“RowDeleting”错误的处理
    ASP.NET中实现文件下载功能
    C#中ref和out的作用和区别
    关于Pascal(帕斯卡)以及Camel(驼峰)命名法
    期末作业验收
    SDN第五次上机作业
  • 原文地址:https://www.cnblogs.com/Apologize/p/6306655.html
Copyright © 2011-2022 走看看