gpt4 book ai didi

swift - 在收集单元格中滑动手势

转载 作者:行者123 更新时间:2023-11-28 08:25:22 25 4
gpt4 key购买 nike

我正在尝试在 Collection View 单元格内做一个滑动手势。我尝试使用本教程 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
}

}

这给了我错误:

'Value of type 'Home' has no member 'handleSwipes'' on the action:#selector line

最佳答案

您需要将 @objc 注释以及 _ 语法添加到您的函数定义中。如果您不添加 _,其 Objective-C 名称将是 functionNameWithSender: 而不是 functionName。所以你的函数定义应该是:

@objc func handleSwipes(_ sender: UISwipeGestureRecognizer)

关于swift - 在收集单元格中滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40197814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com