码迷,mamicode.com
首页 > 移动开发 > 详细

iOS section 随tableview一起滚动

时间:2015-01-31 23:12:23      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

@interface YGSectionHeaderView : UIView
@property NSUInteger section;
@property (nonatomic, weak) UITableView *tableView;
@end
@implementation YGSectionHeaderView

- (void)setFrame:(CGRect)frame{
    CGRect sectionRect = [self.tableView rectForSection:self.section];
    CGRect newFrame = CGRectMake(CGRectGetMinX(frame),
                                 CGRectGetMinY(sectionRect),
                                 CGRectGetWidth(frame),
                                 CGRectGetHeight(frame));
    [super setFrame:newFrame];
}

@end

第二种:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    if ([scrollView isKindOfClass:[UITableView class]])

    {

        CGFloat sectionHeaderHeight = 44;

        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);

        }

    }

}

 

iOS section 随tableview一起滚动

标签:

原文地址:http://www.cnblogs.com/lihaibo-Leao/p/4264778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!