【发布时间】:2018-06-09 21:49:09
【问题描述】:
我想在 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)
}
它不起作用,我无法拖动我的图像视图
我应该为我的表格视图添加什么来执行我的手势?
当我向右或向左滑动按钮时我想要的最终结果图像宽度变宽
谢谢
【问题讨论】:
-
什么是dragButton?
-
这是我要在单元格中移动的图像视图
-
蓝点是单元格?
-
是的,它在单元格中的图像视图
标签: ios swift uitableview uipangesturerecognizer