思路:若header的高度为25,在滑动的时候将scrollView的内容偏移量上衣25,其实他还是粘在上面只不过我们看不到他了。

///---用于判断往上滑还是往下滑

var deltaY:CGFloat = -111

func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

deltaY = -111

}

//---------

override func scrollViewDidScroll(scrollView: UIScrollView) {

super.scrollViewDidScroll(scrollView)

if deltaY >= 0 {

if deltaY - scrollView.contentOffset.y > 0 {

let sectionHeaderHeight:CGFloat = 25;

if scrollView.contentOffset.y <= sectionHeaderHeight*2 && scrollView.contentOffset.y >= 0 {

scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

}else{

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

}

}else{

let sectionHeaderHeight:CGFloat = 25;

if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0){

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

}else{

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0)

}

}

}

else{

deltaY = scrollView.contentOffset.y

}

}

分析:

原理即在往上滑动的时候,将section header 的偏移量往上移动header的高度 ,往下滑动则不管

在scrollViewDidScroll代理方法中

deltaY记录可滑动开始是的偏移量

通过滑动的距离的正负判断上滑还是下滑,这个方法还能判断scrollView上滑下滑。。。。

然后下滑时才设置偏移量为25

scrollViewWillEndDragging方法中记录当滑动停止时是初始位置失效

        

UITableView去掉section的header的粘性的更多相关文章

  1. 下拉刷新和UITableView的section headerView冲突的原因分析与解决方案

    UITableView:下拉刷新和上拉加载更多 [转载请注明出处] 本文将说明具有多个section的UITableView在使用下拉刷新机制时会遇到的问题及其解决方案. 工程地址在帖子最下方,只需要 ...

  2. 快速设置UITableView不同section对应于不同种类的cell

    快速设置UITableView不同section对应于不同种类的cell 本文主要是为了写明如何在UITableView中,一个section对应于一种类型的cell,写起来不凌乱. 在不封装任何类的 ...

  3. 让UITableView的section header view不悬停的方法

    当 UITableView 的 style 属性设置为 Plain 时,这个tableview的section header在滚动时会默认悬停在界面顶端.取消这一特性的方法有两种: 将 style 设 ...

  4. UITableView去掉最后切割线的一种方法

    UITableView以style:UITableViewStylePlain方式创建时.仅仅要有cell,就会有一条黑线 哪怕至于一个cell也会有,如图 在网上找了集中方法,都不好使,比方http ...

  5. IOS UITableView Group&Section

    UItableView 根据数据结构不同 会有不同样式 关键在两个代理 tableviewdelegate&tabledatasourse 下面代码是我实施的Group 在模拟器中 ios6. ...

  6. iOS---》点击uitableview 的section展开或隐藏

    #import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property (weak, nonatomic) IBOu ...

  7. iOS UITableView的Section Footer加入button

    郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 在处理UI ...

  8. ios 更改UITableview中Section的字体颜色

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UILabel *c ...

  9. 从NavigationController 下的UITableView中移除 header

    this.AutomaticallyAdjustsScrollViewInsets = false; 解析:AutomaticallyAdjustsScrollViewInsets为系统自动为适应na ...

随机推荐

  1. es5 and es6

    es5学习地址:http://www.zhangxinxu.com/wordpress/2013/04/es5%E6%96%B0%E5%A2%9E%E6%95%B0%E7%BB%84%E6%96%B9 ...

  2. message from server: "Host 'XXX' is not allowed to connect to this MySQL server

    Access denied for user 'root'@'XXXXX' (using password: YES) mysql命令不正确造成: grant all privileges on *. ...

  3. netperf安装及使用

    一.简介 Netperf是由惠普公司开发的,测试网络栈.即测试不同类型的网络性能的benchmark工具,大多数网络类型TCP/UPD端对端的性能,得到网络上不同类型流量的性能参数.Netperf根据 ...

  4. python3 jason & pickle

    #Author by Andy#_*_ coding:utf-8 _*_import jsonimport pickledef sayhello(name): print('Hello %s' %na ...

  5. R语言实战(一)介绍、数据集与图形初阶

    本文对应<R语言实战>前3章,因为里面大部分内容已经比较熟悉,所以在这里只是起一个索引的作用. 第1章       R语言介绍 获取帮助函数 help(), ? 查看函数帮助 exampl ...

  6. loadrunner将参数文件转换为UTF-8编码

    在使用loadrunner进行参数化的时候,对于有些信息,比如地址.人名等,很多时候需要传入中文,但是有的时候会碰到字符编码不对导致脚本出错. 下面介绍两种loadrunner中可以使用的编码转化为U ...

  7. 获取Mac地址

    netapi32.lib#include <NB30.h>; typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER Name ...

  8. 我们应当怎样学习HTML和CSS

    目标读者:web前端小白.大神请绕路 学习一门新技术,应当找一本经典入门书,在两三天之内快速翻阅完毕,了解其概貌. 然后再制定一个学习路线图(这个路线图绝大多数情况下非书本目录的顺序),接着遵循学习路 ...

  9. POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  10. php开发必备小工具

    /*递归删除目录及目录下的文件*/ function del_dir($dir){ $files = new DirectoryIterator($dir); foreach ($files as $ ...