zoukankan      html  css  js  c++  java
  • 如何去掉UItableview headerview黏性

    有时候使用UITableView所实现的列表,会使用到header view,但是又不希望它粘在最顶上而是跟随滚动而消失或者出现,下面的代码片段就是实现此功能

    1. sectionHeaderHeight 的值要根据自己的而定

    2. _tableView 如果一个类里有多个表格,要明确指明要去掉哪一个表格头的粘性

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {  
        if (scrollView == _tableView) {  
            CGFloat sectionHeaderHeight = 36;
            
            if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {  
                scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);  
            } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {  
                scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);  
            }  
        }  
    }

    其中,header view是指tableview的代理方法:

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  • 相关阅读:
    emberjs初学记要
    自我的一点介绍(七夕礼物)
    JavaScript数据类型
    Vue+Webpack项目配置
    Git知识点整合
    Log4j简单配置解析
    如何明智地向程序员提问
    Navicat连接mysql报错1251
    多表查询sql语句
    PLSQL面向对象
  • 原文地址:https://www.cnblogs.com/dianming/p/6933862.html
Copyright © 2011-2022 走看看