首页 > 代码库 > swif解决手势冲突

swif解决手势冲突

有时候我们在一个大的透明view上添加一个小的view,需要点击透明view时remove掉,但是我们不希望触碰到小的view上也remove就需要实现

UIGestureRecognizerDelegate:

private func addGesture() {

        let tapGesture = UITapGestureRecognizer(target: self, action: Selector("handleTapGesture"))

        tapGesture.delegate = self

        self.addGestureRecognizer(tapGesture)

    }

//MARK:UIGestureRecognizerDelegate  判断当前的view具体是谁

    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {

        

        if touch.view!.isDescendantOfView(点击时候不消失的小view) {

            return false

        }

        return true

    }

 

swif解决手势冲突