思路:若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. [讨论] 这几天来封装Win7用户配置文件丢失的解决方法个人心得

    [讨论] 这几天来封装Win7用户配置文件丢失的解决方法个人心得 prerouting 发表于 2010-5-9 16:50:46 https://www.itsk.com/thread-36634- ...

  2. 遇到 java.io.EOFException 异常的解决办法

    可以试着clean项目后再启动!原因未明

  3. 使用Beautifulsoup爬取药智网数据

    使用Beautifulsoup模块爬取药智网数据 Tips:1.爬取多页时,先用一页的做测试,要不然ip容易被封 2.自己常用的处理数据的方法: reg=re.compile('正则表达式') dat ...

  4. Python学习笔记之字典

    一.创建和使用字典 1.创建字典 phonebook={'Alice':'2341','Beth':'9102','Cecil':'3258'} 2.dict,通过映射创建字典 >>> ...

  5. java selenium验证元素是否存在

    public boolean ElementExist(WebDriver driver,By locator)    {        try {            driver.findEle ...

  6. html中给表格添加斜线

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. 投影转换(AE)

    private void btnOK_Click(object sender, EventArgs e) { try { CheckError(); this.checkEdit1.Enabled = ...

  8. G:数字三角形

    总时间限制: 1000ms 内存限制: 65536kB描述73   88   1   02   7   4   44   5   2   6   5 (图1) 图1给出了一个数字三角形.从三角形的顶部 ...

  9. Joomla

    joomla Joomla实际有两个开源的东西: 1.Joomla内容管理系统即JoomlaCMS(Content Management System, CMS).它是网站的一个基础管理平台.几乎适合 ...

  10. 把word文档中的所有图片导出

    把word文档中的所有图片导出 end