收集单元格中的滑动手势

时间:2016-10-22 22:51:19

标签: swift uicollectionviewcell uiswipegesturerecognizer

我试图在集合视图单元格内进行滑动手势。我试图利用这个教程https://www.youtube.com/watch?v=BZ_Ke0dYpdw,但它不适用于收集单元格,我不知道如何使它在那里工作。这是我到目前为止的代码:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "EventCell", for: indexPath) as! EventCell

cell.delegate = self
cell.index = indexPath.row
var eventsClass = PFObject(className: EVENTS_CLASS_NAME)
eventsClass = eventsArray[(indexPath as NSIndexPath).row]

//swipe gesture
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipes(_:)))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipes(_:)))

leftSwipe.direction = .left
rightSwipe.direction = .right

cell.popoverView.addGestureRecognizer(leftSwipe)
cell.popoverView.addGestureRecognizer(rightSwipe)

   func handleSwipes(sender: UISwipeGestureRecognizer) {
    let eventCell = EventCell()

    if (sender.direction == .left) {
        print("Swipe Left")
    }

    if (sender.direction == .right) {
        print("Swipe Right")
        //let popoverView = CGPointMake(EventCell.popoverView.frame.origin.x + 50.0, self.popoverView.frame.origin.y);
       // popoverView.frame = CGRectMake(popoverView.x, popoverView.y, self.popoverView.frame.size.width, self.popoverView.frame.size.height)
        //popoverView.isHidden = true
    }

}

这给了我错误

  

'类型的价值' Home'没有会员' handleSwipes''在...上   动作:#selector line

1 个答案:

答案 0 :(得分:0)

您需要在函数定义中添加@objc批注和_语法。如果不添加_,则其Objective-C名称将为functionNameWithSender:,而不是functionName。因此,您的函数定义应为:

@objc func handleSwipes(_ sender: UISwipeGestureRecognizer)

相关问题