我想在 UItableviewCell 内左右滑动 UIview,我已经使用 UIPanGestureRecognizer 来实现这一点,下面是附加的源代码。但是,当我尝试滚动 UItableview 时,我的 Uiview 可以上下移动并且无法滚动到 UItableviewcell 即 Superview。谁能告诉我如何管理?提前致谢?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CardSwipeTVCell") as! CardSwipeTVCell
let tapGesture : UIPanGestureRecognizer!
tapGesture = UIPanGestureRecognizer(target: self, action: #selector(ViewController.tapEdit(_:)))
cell.cardView.addGestureRecognizer(tapGesture!)
cell.cardView.tag = indexPath.row
tapGesture!.delegate = self
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
func tapEdit(_ recognizer: UIPanGestureRecognizer)
{
print(recognizer.view?.tag as Any)
let sender = recognizer.view?.tag as Any
let indexPath = IndexPath(row: sender as! Int, section: 0)
let cell = self.cardTableView.cellForRow(at: indexPath) as? CardSwipeTVCell
cell?.cardView.backgroundColor = UIColor.black
let card = recognizer.view!
let point = recognizer.translation(in: view)
card.center = CGPoint(x: (cell?.center.x)! + point.x, y: (cell?.center.y)! + point.y)
if recognizer.state == UIGestureRecognizerState.ended
{
UIView.animate(withDuration: 0.3, animations: {
card.center = (cell?.center)!
})
}
}
另一个问题是当我点击第二个单元格时,我的视图消失了?您的帮助将不胜感激。