iosswiftcollectionviewscroll-position

How to pass option set as parameter for scrollpositions?


I want to pass option set for scroll position as parameter argument, but facing some issue.

Please can anyone write how to do it?

func selectCurrentWallpaperCell() { //want to pass parameter here
        let currentWallpaperID = self.wallpaperManager.currentWallpaperID
        if let index = self.wallpapers.index(where: { $0.id == currentWallpaperID }) {
            let indexPath = IndexPath(item: index, section: 0)
            self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: UICollectionViewScrollPosition()) // how to use in scrollposition?
        }
    }

Solution

  • let options: UICollectionViewScrollPosition = [.top, .centeredVertically]
    self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: options)
    

    Reference: OptionSet