【问题标题】:Double tap Gesture on UICollectionViewCell?在 UICollectionViewCell 上双击手势?
【发布时间】:2016-01-22 04:48:16
【问题描述】:

我想双击 UICollectionViewCell 以像 OkCupid 应用程序 一样喜欢个人资料。我在收藏视图上应用了点击手势,但它不起作用。

当我每次尝试双击单元格时,didSelectCollectionViewCell 方法调用。

【问题讨论】:

    标签: ios swift uicollectionviewcell uitapgesturerecognizer


    【解决方案1】:

    你得到的错误:无法调用非函数类型'UICollectionView!'的值是因为你尝试使用了错误的方法。

    请尝试使用这个:

    var selectedIndexPath: NSIndexPath = self.collectionView.indexPathForItemAtPoint(pointInCollectionView)
    

    【讨论】:

      【解决方案2】:

      您必须将双击手势识别器添加到集合视图而不是单元格。在其动作选择器中,您可以确定双击哪个单元格

      override func viewDidLoad() {
           var doubleTapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "didDoubleTapCollectionView:")
           doubleTapGesture.numberOfTapsRequired = 2  // add double tap
           self.collectionView.addGestureRecognizer(doubleTapGesture)
      }
      
      func didDoubleTapCollectionView(gesture: UITapGestureRecognizer) {
           var pointInCollectionView: CGPoint = gesture.locationInView(self.collectionView)
           var selectedIndexPath: NSIndexPath = self.collectionView(forItemAtPoint: pointInCollectionView)
           var selectedCell: UICollectionViewCell = self.collectionView.cellForItemAtIndexPath(selectedIndexPath)
           // Rest code
      }
      

      【讨论】:

      • 以上代码报错Cannot call value of non-function type 'UICollectionView!'
      • 在您的收藏视图中听起来像错误检查您的收藏视图
      • 以上这些方法不存在,请在回复时提供有效的可编译代码,以免混淆其他初学者。
      【解决方案3】:

      您是否将UITapGestureRecognizer 属性numberOfTapsRequired: 设置为2?

      【讨论】:

        【解决方案4】:

        UICollectionviewcell 而不是 UIcollectionView 上应用 UITapGesture 并在自定义 UICollectionViewCell 中处理选择并将属性 numberofTapsRequired 设置为 2 ... ..

        【讨论】:

          猜你喜欢
          • 2013-09-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-13
          相关资源
          最近更新 更多