Martin Koles Martin Koles - 4 months ago 28
iOS Question

Scroll UICollectionView to section header view

The code below scrolls to the right cell in

UICollectionView
, but the section header view is hidden behind
UINavigationBar
in my case. I believe I should use
scrollRectToVisible
instead and my question is, what is the right way to calculate the
CGRect
(y position) when the
numberOfRows
in a given
section
is variable.

- (void)scrollToPricing:(NSUInteger)row {

[self.collectionView scrollToItemAtIndexPath:
[NSIndexPath indexPathForItem:0
inSection:row]
atScrollPosition:UICollectionViewScrollPositionTop
animated:YES];
}

Answer

I think this may help you

UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath];

Then you can access the location through attributes.frame

Comments