zoukankan      html  css  js  c++  java
  • Tableview如何实现流畅的展开折叠?

    上周做了一个tableview的展开折叠,好久不用,生疏好多,结果各种纠结蛋疼,效果各种不好,索性不弄了,浪了两天之后,周一来了灵感突发,一气呵成,效果感觉还不错,废话不多说,说下具体流程

      1.tableview的style:UITableViewStylePlain(很重要,直接影响动画视觉效果)

      2.通过scrollview的代理控制禁止header悬停,这里就很蛋疼了(万恶的Oc),设置成让他悬停再禁止掉就是为了动画的视觉效果醉了醉了下面是代码

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
      if (scrollView == self.tableView)
      {
        CGFloat sectionHeaderHeight = 100 * KY_Proportion; //sectionHeaderHeight
        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);
        }
      }
    }
    

       3.这里也是为了视觉效果,上面禁止悬停实现了,可是发现tableview展开折叠的时候,footer也会悬停,因此直接将footer设置为0,在header上做了一个假的footer,哈哈哈哈哈哈哈哈

      4.也很重要,进行UI和数据源操作时采用删除和添加行的方式,动画就是删除向上插入向下。

    Ok了,撸主写完后看了下,tableview展开折叠很流畅,很开心有木有!!!

  • 相关阅读:
    Median Value
    237. Delete Node in a Linked List
    206. Reverse Linked List
    160. Intersection of Two Linked Lists
    83. Remove Duplicates from Sorted List
    21. Merge Two Sorted Lists
    477. Total Hamming Distance
    421. Maximum XOR of Two Numbers in an Array
    397. Integer Replacement
    318. Maximum Product of Word Lengths
  • 原文地址:https://www.cnblogs.com/ycq-firstBlood/p/5841336.html
Copyright © 2011-2022 走看看