iOS 控制section不懸停 --- iOS開發系列 ---項目中成長的知識八

通常狀況下,tableview中的section是會默認隨着tableview的滾動而滾動的,而是會等到屬於這個section的cell滑完事後,而後往上頂(不知道你們能不能聽懂=_=!)spa

有些時候這樣顯得不是很美觀,並且有些項目是須要主要針對section而不是row 進行操做,因此這個時候控制section不懸停就顯得很重要code

 

這裏有兩種方法,直接貼代碼吧blog

 

  • 第一種:
 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 //}

 

 

但願能幫助到你們!io

 

 

在項目中我使用的是第一種方法table

相關文章
相關標籤/搜索