zoukankan      html  css  js  c++  java
  • UITableView去掉section的header的粘性

    思路:若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方法中记录当滑动停止时是初始位置失效

            

  • 相关阅读:
    [UOJ#391]GEGEGE
    [GOODBYE WUXU][UOJ]
    codeforce 1110F
    [atcoder][abc123D]
    [atcoder][agc001]
    Luogu1070-道路游戏-动态规划
    Luogu 2577[ZJOI2005]午餐
    Luogu 1169 [ZJOI2007]棋盘制作
    Luogu 1273 有线电视网
    Luogu 2279 [HNOI2003]消防局的设立
  • 原文地址:https://www.cnblogs.com/pigface/p/5385950.html
Copyright © 2011-2022 走看看