美文网首页
iOS怎么禁止子视图响应父视图的手势

iOS怎么禁止子视图响应父视图的手势

作者: __weiliang | 来源:发表于2021-10-12 11:04 被阅读0次

iOS做弹窗的时候,通常加一个黑色半透明的蒙板,点击蒙板弹窗消失,所以给蒙板添加单击手势,这个时候弹窗上面的点击手势就失效了,解决办法如下


override init(frame: CGRect) {
        super.init(frame: UIScreen.main.bounds)
        
        backgroundColor = UIColor.black.withAlphaComponent(0.39)
        //添加手势
        let tap = UITapGestureRecognizer(target: self, action: #selector(hide))
        tap.delegate = self
        addGestureRecognizer(tap)
  }

//实现代理
extension BottomPopView: UIGestureRecognizerDelegate {
    override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        let point = gestureRecognizer.location(in: self)
        return !tableView.frame.contains(point)
    }
}

相关文章

网友评论

      本文标题:iOS怎么禁止子视图响应父视图的手势

      本文链接:https://www.haomeiwen.com/subject/unedoltx.html