I'm preparing a GridView with all orientation support (height & width resizing) and paging enabled.
In my sample in have taken a 3*3 Grid and to show it like that I have added some dummy transparent cell at the last page.
The issue is when I'm at last page and there I'm changing my orientation from landscape to portrait the pagination doesn't work.
I have used this code in willRotateToInterfaceOrientation
:
CGPoint scrollTo = CGPointMake(self.frame.size.width * mPageControl.currentPage, 0);
[self setContentOffset:scrollTo animated:YES];
But still page moves to a page before the last page when going from landscape to portrait and while changing portrait to landscape it works fine.
I manage to solve this by setting notification when screen orientation changes and reloading cell which set itemsize according to screen orientation and setting indexpath to previous cell. This does work with flowlayout too. Here is the code i wrote:
Then i'm calling a method whenever orientation is changing
Had the same problem, my UICollectionView was paginated, when I scrolled to page 2 in portrait mode and then switched to landscape, the content offset would be set to (72, 0), and this would persist.
The controller was registered for orientation changes where it invalidated the layout, but setting the offset in there didn't help.
What did help was setting the offset inside the layout class' prepareForLayout method. I used
Ceiling is used because floor would always go back to the previous page (and page 0 always paginates fine).
If you're not using a custom layout, you can still subclass flow layout and override that one function.