gpt4 book ai didi

ios - Swift:单元格 TableviewCell 中的手势不起作用

转载 作者:行者123 更新时间:2023-11-30 11:25:35 24 4
gpt4 key购买 nike

我想在 UITableViewCell 中添加 UIGestureRecognizer 但它不起作用。

这是我的代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

//On lien le TableViewCell
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? FeedCell
cell?.selectionStyle = .none

let pan = UIPanGestureRecognizer(target: self, action: #selector(cell?.handlePan(recognizer:)))
pan.delegate = self as? UIGestureRecognizerDelegate
cell?.dragButton.addGestureRecognizer(pan)

cell?.view(post: posts[indexPath.row], user: users[indexPath.row]); //On passe l'objet a l'index i a la fonction view du TableViewCell pour l'affichage

return cell!;
}

以及在tableviewcell中

@objc func handlePan(recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translation(in: dragButton)

recognizer.view!.center = CGPoint(x: recognizer.view!.center.x + translation.x, y: recognizer.view!.center.y + translation.y)

recognizer.setTranslation(CGPoint.zero, in: self.containerDragView)
}

它不起作用,我无法拖动我的 ImageView

我应该为我的表格 View 添加什么来执行我的手势?

滑动左右按钮时我想要的最终结果左右图像宽度变宽

谢谢

Result

最佳答案

在你的tableviewcell类中尝试这个实现委托(delegate)UIGestureRecognizerDelegate

我认为问题就在这里。 pan.delegate = self 作为? UIGestureRecognizerDelegate

这样设置委托(delegate)。

pan.delegate = cell

关于ios - Swift:单元格 TableviewCell 中的手势不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50778827/

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