如何将选项集作为滚动位置的参数传递?

How to pass option set as parameter for scrollpositions?

我想将滚动位置的选项集作为参数参数传递,但遇到了一些问题。

请问有谁能写下怎么做吗?

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

参考:OptionSet

UICollectionViewScrollPosition conforms to OptionSet 协议,因此您可以传递两个或更多选项,就像 Suhit 已经回答的那样。
您只需要让您的函数接受 UICollectionViewScrollPosition 作为参数并将其作为参数传递给 collectionview 的 selectItem: 方法。