Gemini icon indicating copy to clipboard operation
Gemini copied to clipboard

Scroll to specific item programmatically using current animation

Open kokitang opened this issue 6 years ago • 0 comments

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?

kokitang avatar Sep 05 '18 03:09 kokitang