zepojo/UPCarouselFlowLayout

`scrollToItemAtIndexPath:atScrollPosition:animated:` not working

irodrigo17 opened this issue · 3 comments

Just noticed that scrollToItemAtIndexPath:atScrollPosition:animated: of the UIScrollView is not working properly when using this layout.

I tried with all the UICollectionViewScrollPosition options, even though the CenteredVertically and CenteredHorizontally should probably be the only supported ones, depending on the layout direction.

I would be glad to add support for it and send a pull request if somebody can provide some basic direction to get me started.

In my case, selectItemAtIndexPath:animated:scrollPosition: caused improper centre point of currently focussed item.
performing self.view.layoutIfNeeded() right before self.collectionView.selectItemAtIndexPath(NSIndexPath(forRow: indexPath, inSection: 0), animated: true, scrollPosition: .CenteredHorizontally) fixed this issue.

Hope that this will also fix your issue.

Thanks @rafalkitta! I'm not using this library anymore, but that definitely makes sense, and looks like a very simple solution.