Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: How to select and scroll to a specific cell in a collectionView in swift 3?

I would like to select and scroll to a specific indexPath in a collectionView with centring it. I found that functions, but impossible to combine them:

collectionView.selectItem(at: indexPath, animated: true, scrollPosition: UICollectionViewScrollPosition.centeredVertically)
collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: true)

Thanks in advance.

like image 708
ΩlostA Avatar asked Sep 06 '17 15:09

ΩlostA


1 Answers

You can pass options set [.centeredHorizontally,.centeredVertically]

collectionView.scrollToItem(at: indexPath, at: [.centeredHorizontally,.centeredVertically], animated: true)
like image 118
Ihar Katkavets Avatar answered Oct 02 '22 13:10

Ihar Katkavets