有时候我们在一个大的透明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
}
时间: 2024-10-10 12:50:00