I would like to scroll collection view to some offscreen cell without animation and get position of that cell after scrolling. The problem is that collection view scrolls correctly (visually) but cell frame remains offscreen. Here is my code:
NSIndexPath *path = [fetchedResultsController indexPathForObject:objectInCollection];
[collectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
[collectionView layoutSubviews]; // or 'layoutIfNeeded', doesn't matter
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:path];
cellFrame = [cell.superview convertRect:cell.frame toView:nil]; // still not refreshed
I can propose that collection view applies scrolling not immediately, so I would like to find approach to apply the scrolling.
--- UPDATE ---
The collection view is in previous view controller (so I scroll it from code and then pop visible view controller).
Cell frame remains offscreen even in viewDidAppear:
method of previous view controller. To be exact, [cell.superview convertRect:cell.frame toView:nil];
returns frame without contentOffset
of collection view. So CGRectOffset([cell.superview convertRect:cell.frame toView:nil], 0, -collectionView.contentOffset.y)
returns correct cell frame on screen.