I have a view(superview) which I can move by pan gesture, This view has subview(UIButton) with TouchDown Event. But when I press button(touchdown event handled) and continue move finger my superview start handling pan gesture method. How disable handling pan gesture method of superview when I touchdown its subview?
for disabling touch events on UIView's subviews you can add this extension to UIViewController
:
extension UIViewController:UIGestureRecognizerDelegate {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
tap.delegate = self
}
func dismissKeyboard() {
view.endEditing(true)
}
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if (touch.view!.isDescendantOfView(self.view) && touch.view != self.view){
return false
}
return true
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.