UITapGestureRecognizer 和 didSelectRowAt 点击事件冲突

在UIView中创建了一个UITableView ,但是tableView的点击事件 和 UITapGestureRecognizer 的冲突。

本篇文章是在 此文章上做的修改。
http://blog.csdn.net/yimiyuangguang/article/details/70831559

解决方法:

  public func showView(){
        UIApplication.shared.keyWindow?.addSubview(self)
        
        self.backgroundColor = UIColor.red
        let tapG = UITapGestureRecognizer(target: self, action: #selector(dismissView))
        tapG.delegate = self
        self.addGestureRecognizer(tapG)
 }
extension LeftView :UIGestureRecognizerDelegate{
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
       
        let touchClass = NSStringFromClass((touch.view?.classForCoder)!)
        let supClass = NSStringFromClass((touch.view?.superview?.classForCoder)!)
        
        if touchClass == "UITableView" || touchClass == "UICollectionView" ||
            supClass == "UITableView" || supClass == "UICollectionView" ||
            touchClass == "UITableViewCellContentView" || supClass == "UITableViewCell"
            {
            return false
        }
        
        return true
    }
}

你可能感兴趣的:(UITapGestureRecognizer 和 didSelectRowAt 点击事件冲突)