zoukankan      html  css  js  c++  java
  • iOS 控制section不悬停 --- iOS开发系列 ---项目中成长的知识八

    一般情况下,tableview中的section是会默认随着tableview的滚动而滚动的,而是会等到属于这个section的cell滑完过后,然后往上顶(不知道大家能不能听懂=_=!)

    有些时候这样显得不是很美观,而且有些项目是需要主要针对section而不是row 进行操作,所以这个时候控制section不悬停就显得很重要

    这里有两种方法,直接贴代码吧

    • 第一种:
     1 #pragma -mark 控制section不悬停
     2 
     3 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
     4 
     5 {
     6 
     7     NSLog(@"%f",scrollView.contentOffset.y);
     8 
     9     CGFloat sectionHeaderHeight = 40;
    10 
    11     if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
    12 
    13         scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    14 
    15     }
    16 
    17     else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
    18 
    19         scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    20 
    21     }
    22 
    23 }
    • 第二种:
    1 //- (void)setFrame:(CGRect)frame{
    2 
    3 //    CGRect sectionRect = [self.tableView rectForSection:self.section];
    4 
    5 //    CGRect newFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame)); [super setFrame:newFrame];
    6 
    7  
    8 
    9 //}

    希望能帮助到大家!

    在项目中我使用的是第一种方法

  • 相关阅读:
    Eclipse用法和技巧二:自动生成Main方法1
    java 基于JDK中的源码总结下String二
    700.Search in a Binary Search Tree
    722.Remove Comments
    95. Unique Binary Search Trees II(dfs经典题目)
    20.Valid Parentheses
    28.Implement strStr()
    888.Fair Candy Swap
    14.Longest Common Prefix
    234.Palindrome Linked List
  • 原文地址:https://www.cnblogs.com/WayneLiu/p/5062094.html
Copyright © 2011-2022 走看看