【问题标题】:How to pass option set as parameter for scrollpositions?如何将选项集作为滚动位置的参数传递?
【发布时间】:2018-04-13 13:34:21
【问题描述】:

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

谁能写下怎么做?

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?
        }
    }

【问题讨论】:

    标签: ios swift collectionview scroll-position


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      let options: UICollectionViewScrollPosition = [.top, .centeredVertically]
      self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: options)
      

      参考:OptionSet

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-18
        • 2018-01-23
        • 1970-01-01
        相关资源
        最近更新 更多