标签:
const NSUInteger numberOfSections = self.numberOfSections;
const UIEdgeInsets contentInset = self.contentInset;
const CGPoint contentOffset = self.contentOffset;
const CGFloat sectionViewMinimumOriginY = contentOffset.y + contentInset.top + headerViewInsets.top;
// Layout each header view
for(NSUInteger section = 0; section < numberOfSections; section++)
{
UIView* sectionView = [self headerViewForSection:section];
if(sectionView == nil)
continue;
const CGRect sectionFrame = [self rectForSection:section];
CGRect sectionViewFrame = sectionView.frame;
sectionViewFrame.origin.y = ((sectionFrame.origin.y < sectionViewMinimumOriginY) ? sectionViewMinimumOriginY : sectionFrame.origin.y);
// If it‘s not last section, manually ‘stick‘ it to the below section if needed
if(section < numberOfSections - 1)
{
const CGRect nextSectionFrame = [self rectForSection:section + 1];
if(CGRectGetMaxY(sectionViewFrame) > CGRectGetMinY(nextSectionFrame))
sectionViewFrame.origin.y = nextSectionFrame.origin.y - sectionViewFrame.size.height;
}
// TPLOG(@"%f",sectionViewFrame.origin.y);
[sectionView setFrame:sectionViewFrame];
}
这个是当tableVIew的
UIEdgeInsets改变的时候,tableView的区头滑动不正常的处理,其中[self rectForSection:section]返回的是区头距离表头的绝对高度,不会改变,UIView* sectionView = [self headerViewForSection:section而这个view的frame确是相对的。这里的处理的逻辑就是当视图滑动的时候,在区头未滑倒顶部的时候,其view的高度设置成绝对高度,当在顶部停留的时候,再设置程偏移量,可实现在顶部的停留。
标签:
原文地址:http://www.cnblogs.com/andi0816/p/5619915.html