【问题标题】:Remove gesture for a specific tableview cell删除特定表格视图单元格的手势
【发布时间】:2019-05-20 18:43:22
【问题描述】:

已回答了相同的问题,但所有推荐的方法都不适合我: How to remove long gesture in UIcollectionViewCell particular cell on selection cell?

我有一个表格视图,在整个表格视图上添加了两个手势,UIPanGestureRecognizer 和 `UITapGestureRecognizer。它使某些单元格没有像我预期的那样响应,所以我想从某个单元格中删除它们,这可能吗?如果是,怎么做?

非常感谢您提前提供的帮助

【问题讨论】:

  • 您可以发布您的代码以便我更好地帮助您吗?

标签: ios swift uitableview uitapgesturerecognizer uipangesturerecognizer


【解决方案1】:

好的,只有一种方法可以做到这一点:

class MyViewController: UIViewController {

    @IBOutlet private var collectionView: UICollectionView!

    private let panGesture = UIPanGestureRecognizer()
    private let tapGesture = UITapGestureRecognizer()

    override func viewDidLoad() {
        super.viewDidLoad()
        panGesture.delegate = self
        tapGesture.delegate = self

        // Code to assign Gesture Recognizer
    }
}

// You should conform your controller to UIGestureRecognizerDelegate
extension MyViewController: UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        let touchLocation = touch.location(in: collectionView)
        guard let indexPath = collectionView.indexPathForItem(at: touchLocation) else {
            return true
        }
        // let's assume that you want to disable second cell (indexPath.row starts from 0)
        let disabledRow = 1
        return indexPath.row != disabledRow
    }
}

如果您发布代码,我可以为您提供更好的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多