简体   繁体   English

如何在父视图中禁用点击手势?

[英]How can disable tap gesture in parent view?

I have 2 views. 我有2个意见。 View 1 is superview and i added tap gesture in superview. 视图1是超级视图,我在超级视图中添加了轻击手势。 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? 视图2是Collectionview,当我单击collectionview单元格时,在Collectionview中的事件didSelectItemAt和在superview中的点击手势都被调用。当我单击collectionview单元格时,如何在超级视图中禁用点击手势?

You can try to set userInteractionEnabled to false on your parent view. 您可以尝试在父视图上将userInteractionEnabled设置为false

Eg view.userInteractionEnabled = false 例如view.userInteractionEnabled = false

Docs at userInteractionEnabled userInteractionEnabled上的文档

--UPDATE -更新

You can implement gestureRecognizer delegate,a nd then check if it is your view that called on touch property; 您可以实现gestureRecognizer委托,然后检查是否在您的视图上调用了touch属性;

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if touch.view == {{youview}} {
        return false
    }
    return true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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