Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll to specific item programmatically using current animation #24

Open
kokitang opened this issue Sep 5, 2018 · 0 comments
Open

Comments

@kokitang
Copy link

kokitang commented Sep 5, 2018

I'm using to following code to set the flow layout in example project's scale up horizontal animation. The result of this setting is only shows about 40px width of previous item, and the next item is invisible while paging animation is done.

// Setting of UICollectionViewFlowLayout let layout = UICollectionViewPagingFlowLayout() layout.scrollDirection = scrollDirection layout.itemSize = CGSize(width: view.bounds.width - 120, height: view.bounds.height - 400) layout.sectionInset = UIEdgeInsets(top: 200, left: 80, bottom: 200, right: 40) layout.minimumLineSpacing = 10 layout.minimumInteritemSpacing = 10 collectionView.collectionViewLayout = layout collectionView.decelerationRate = UIScrollViewDecelerationRateFast

However, if I trying to implement an action which scroll to the previous item when user click on the previous item. I'm using the following codes. The result comes out is the previous cell moved to center, and the next/last cell are displayed on right/left with 20px width respectively.

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true) }

How to do the programatic scrolling which can be same of the animation that performed by paging scrolling?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant