KelvinJin / AnimatedCollectionViewLayout

A UICollectionViewLayout subclass that adds custom transitions/animations to the UICollectionView without effecting your existing code.
MIT License
4.75k stars 351 forks source link

Autoplay feature #21

Open pballada opened 7 years ago

pballada commented 7 years ago

Hi, I'm working with an autoplay feature and have two questions.

First one is that to go to next indexPath, I'm using the scrollToItem function, but is not always working as expected, sometimes it scrolls and sometimes not.

collectionView.scrollToItem(at: nextIndexPath, at: UICollectionViewScrollPosition.left, animated: true)

Maybe I'm missing something here..

And second, there's a way to change the speed of the animation of scrollToItem? Looks it's fixed by the system..

Thanks!

pballada commented 7 years ago

Actually, autoplay works with all animations with a Timer and scrollToItem, except the crossfade animation, not sure why. Any light will be welcome.

No luck neither related to the speed of the animation when using scrollToItem.

thanks for the library!

kelsheikh commented 7 years ago

Hi, I have also had trouble using scrollToItem with this UICollectionViewLayout subclass in an autoplay feature. The cell does not seem to get centered when I use LinearCardAttributesAnimator and then causes issues going forward. I have tried adding dispatch delays and wrapping in a UIView.animate but have had no luck. I love this library and just needed to be able to use scrollToItem.

collectionView.scrollToItem(at: IndexPath, at: centeredHorizontally, animated: true)

Was there any kinda of fix or workaround for this to scroll to a specific cell and have it centered on cell?

romansorochak commented 6 years ago

@mixmastertube @kelsheikh try to use scrollToVisibleRect which is inherited from UIScrollView

mstroshin commented 5 years ago

Hi, I use page layout and I can scroll the pages forward, but I can't do it backwards.

collectionView.scrollToItem(at: IndexPath, at: centeredHorizontally, animated: true)

let rect = self.collectionView.layoutAttributesForItem(at: indexPath)!.frame self.collectionView.scrollRectToVisible(rect, animated: animated)

Both do not work. Сan you help with this problem?

pballada commented 3 years ago

Manage to make it work for the crossfade using:

collectionView.setContentOffset(CGPoint(x: CGFloat(indexPath.row) * collectionView.frame.size.width, y: 0), animated: animated)

instead of: collectionView.scrollToItem(at: indexPath, at: UICollectionView.ScrollPosition.left, animated: animated)