IOS - Sticky UICollectionView Header (e.g. Apple App Store)

I am trying to create a header similar to the one in the App Store. Where, when the user drags down, the title stays in place and only the cells scroll down. But when the user drags up, the title and cells scroll up.

What I have done so far is to set my background view collectionView

to the image I want to stick to and set contentInsets

to collectionView

below the image. This way, when the user drags down, the image stays in place. But when the user pulls in, my cameras view the image (I want the image to scroll up with the cells). I think I am going to get it wrong. Thank.


 UIView *back = [UIView new];
 UIImageView *backImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 320)];
 backImage.image = [UIImage imageWithData:coverData];
 [back addSubview:backImage];
 self.collectionView.backgroundView = back;

      


 [self.collectionView setContentInset:UIEdgeInsetsMake(300, 0, 0, 0)];

      

EDIT I used the tutorial on this , but it does the opposite of what I want, and I'm not sure how to modify this code to suit my needs.

+3


source to share


1 answer


OK I understood. If you are using the tutorial posted from the linked question -

Edit

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

      



To that

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

      

0


source







All Articles