iOS UITableView取消SectionView停滞效果

对网上一些想法做了参考。
第一种方法通过验证觉得不太好(不推荐实用)

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        CGFloat sectionHeaderHeight = 40;
        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);
        }
    }


第二种方法:通过对自定义sectionView的setFrame的重写,重新设置section的Y值。

#import "ZWSectionHeadView.h"
#define APP_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width   // 屏幕的宽度
#define kHeadView_Height 44
@implementation ZWSectionHeadView

#pragma mark - init
#pragma mark -
+ (ZWSectionHeadView *)showWithName:(NSString *)sectionName
{
    ZWSectionHeadView  *sectionView = [[ZWSectionHeadView alloc]initWithFrame:CGRectMake(0, 0, APP_SCREEN_WIDTH, kHeadView_Height)];
    sectionView.backgroundColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.8 alpha:0.2f];

    // title
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 22, APP_SCREEN_WIDTH - 20, 20)];
    titleLabel.textColor = [UIColor blueColor];
    titleLabel.text = sectionName;
    titleLabel.font = [UIFont systemFontOfSize:16.0f];
    [sectionView addSubview:titleLabel];

    return sectionView;
}

#pragma mark - sectionHeight
+ (CGFloat)getSectionHeight
{
    return kHeadView_Height;
}

#pragma mark - setter
- (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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值