美文网首页
iOS_UICollectionView 添加子视图内容偏移M

iOS_UICollectionView 添加子视图内容偏移M

作者: wahkim | 来源:发表于2018-12-06 15:54 被阅读12次

问题:由于CollectionView没有像TableView的tableHeaderView 现在需求需要,采用的办法是添加子视图,让其内容偏移

//设置滚动范围偏移
    self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(kAdaptedWidth(150), 0, 0, 0);
    //设置内容范围偏移
    self.collectionView.contentInset = UIEdgeInsetsMake(kAdaptedWidth(150), 0, 0, 0);
//    self.collectionView.alwaysBounceVertical = YES;
    RDBookcaseReusableView *temp = [[RDBookcaseReusableView alloc]initWithFrame:CGRectMake(0, -kAdaptedWidth(150), kSCREEN_WIDTH, kAdaptedWidth(150))];
    [self.collectionView addSubview:temp];

这样写的话效果出来了 但是mj_header 和 mj_footer 也随之偏移,看不见了。

解决办法

    self.collectionView.mj_header.ignoredScrollViewContentInsetTop = self.collectionView.contentInset.top;
// 忽略偏移 

相关文章

网友评论

      本文标题:iOS_UICollectionView 添加子视图内容偏移M

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