美文网首页
设置contentInset时MJRefresh下拉刷新异常

设置contentInset时MJRefresh下拉刷新异常

作者: wustzhy | 来源:发表于2020-05-18 15:14 被阅读0次

    需求:
    为了实现tableView和collectionView顶部插入一个tip label,可随着滚动而滑出界面

    做法:
    (如果collectionView有headerView该多好,但只有tableView才有...)

    - (void)addHeaderForCollectionView:(UICollectionView *)collectionView {
        CGFloat headerH = 44;
        collectionView.contentInset = UIEdgeInsetsMake(headerH, 0, 0, 0);
        
        UIView *headerView;
        [collectionView addSubview:({
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -headerH, SCREEN_WIDTH, headerH)];
            view.backgroundColor = [UIColor clearColor];
            headerView = view;
            view;
        })];
        
        UILabel *tipLabel;
        [headerView addSubview:({
            UILabel *label = [[UILabel alloc] init];
            label.font = kFont(10);
            label.textColor = kColor(@"#999999");
            label.numberOfLines = 0;
            label.textAlignment = NSTextAlignmentCenter;
            label.text = @"优质内容将会被小编精选在首页—推荐中曝光哦~\n快去发布优质内容上首页啦";
            tipLabel = label;
            label;
        })];
        [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.mas_equalTo(0);
        }];
    }
    

    bug:
    设置了tableView和collectionView的contentInset.top值,发现collectionView下拉刷新时,MJ刷新控件 与 tipLabel展示位置重叠了

    solution:
    flowLayout.sectionInset.top 或者 flowLayout.headerInset, 均可以.
    (CHTCollectionViewWaterfallLayout)

    flowLayout.sectionInset = kFeedSecitonInset;// UIEdgeInsetsMake(4, 4, 4, 4);
    
    flowLayout.headerInset = UIEdgeInsetsMake(self.headValue.floatValue, 0, 0, 0);
    

    相关文章

      网友评论

          本文标题:设置contentInset时MJRefresh下拉刷新异常

          本文链接:https://www.haomeiwen.com/subject/ofmuohtx.html