4

I have added a search bar in a SectionHeader cell from the UICollectionView.

Currently I'm hiding the view by moving the Y-offset up.

[self.collectionView setContentOffset:CGPointMake(0, 44)];

This works perfectly when the height of my offset is bigger than my view. (vertical scrollbar) But when the cells fit into my view, the search bar keeps still visible. (no vertical scrollbar)

Any idea?

Ty

Jonathan
  • 480
  • 6
  • 9

2 Answers2

2

What I did was subclass UICollectionViewFlowLayout and override the method:

- (CGSize)collectionViewContentSize {
    CGSize size = [super collectionViewContentSize];

    // add viewHeight to allow enough room for view to be hidden
    if (size.height < self.collectionView.frame.size.height + viewHeight) {
        size.height = self.collectionView.frame.size.height + viewHeight;
    }

    return size;
}

This does mean people can scroll a little bit on your collectionView when the size of the content is smaller than the bounds of your collectionView.

Shizam
  • 9,627
  • 8
  • 51
  • 82
khangsile
  • 101
  • 1
  • 7
1

Sounds like you may just need to set alwaysBounceVertical:YES on your collectionView.

Samuel
  • 401
  • 2
  • 10