简体   繁体   中英

UITapGestureRecognizer not working on top points on UIView

I'm using a UIView with a UITapGestureRecognizer. On the other hand I have a tap recognizer on ViewController's container view,

Now when i tap on my inner view, it calls handler,

BUT when I tap on for example 40 upper points of it, it doesn't work and container's tap recognizer fires!!!, actually i'm sure it's inside the UIView, i'm sure as I changed it's background to a different color, and on the other hand, there isn't any other views on this view, too!

It's really annoying, i've tested everything, hiding all views, disabling other recognizers and so on! And it's not my first time using this UI TAP RECOGNIZER :///

    view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(viewController.dismissKeyboard(_:))))
    viewWrite.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(viewController.viewPressed(_:))))

EDIT::

I found that even when i touch here on my UITextView, the main container's tap event loads!! but other points of view, no! ::

这里!!

You can try implementing UIGestureRecognizerDelegate

eg.

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    if (gestureRecognizer == recoginiser1 && wrongview1) return false
    if (gestureRecognizer == recoginiser2 && wrongview2) return false
    else return true;
}

wrongview means something like this.

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    if (gestureRecognizer == recognizer1){
    let point = touch.locationInView(self.view)
        if CGRectContainsPoint(textView.frame, point) == true {
            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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM