简体   繁体   中英

How can disable tap gesture in parent view?

I have 2 views. View 1 is superview and i added tap gesture in superview. View 2 is Collectionview and when I click on collectionview cell both event didSelectItemAt in Collectionview and tap gesture in superview called.How can disable tap gesture in supperview when I click on collectionview cell?

You can try to set userInteractionEnabled to false on your parent view.

Eg view.userInteractionEnabled = false

Docs at userInteractionEnabled

--UPDATE

You can implement gestureRecognizer delegate,a nd then check if it is your view that called on touch property;

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if touch.view == {{youview}} {
        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