How to make Supplementary View float in UICollectionView as Section Headers do in UITableView plain style

后端 未结 13 703
逝去的感伤
逝去的感伤 2020-11-27 09:35

I\'m struggling to achieve a \"floating section header\" effect with UICollectionView. Something that\'s been easy enough in UITableView (default b

13条回答
  •  隐瞒了意图╮
    2020-11-27 10:27

    I ran this with vigorouscoding's code. However that code did not consider sectionInset.

    So I changed this code for vertical scroll

    origin.y = MIN(
                  MAX(contentOffset.y, (CGRectGetMinY(firstCellAttrs.frame) - headerHeight)),
                  (CGRectGetMaxY(lastCellAttrs.frame) - headerHeight)
               );
    

    to

    origin.y = MIN(
               MAX(contentOffset.y, (CGRectGetMinY(firstCellAttrs.frame) - headerHeight - self.sectionInset.top)),
               (CGRectGetMaxY(lastCellAttrs.frame) - headerHeight + self.sectionInset.bottom)
               );
    

    If you guys want code for horizontal scroll, refer to code aove.

提交回复
热议问题