Ios UIgestureRecognitors没有响应

Ios UIgestureRecognitors没有响应,ios,uiview,uigesturerecognizer,Ios,Uiview,Uigesturerecognizer,我有许多弹出视图保存为视图控制器的属性。它们仅在显示时添加到视图中,在隐藏时从视图中删除。一切都正常,但我修改了代码以简化事情,它不再工作了 以下是我如何创建和添加手势识别器的示例: UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)]; [self.totalPowerPopUpVie

我有许多弹出视图保存为视图控制器的属性。它们仅在显示时添加到视图中,在隐藏时从视图中删除。一切都正常,但我修改了代码以简化事情,它不再工作了

以下是我如何创建和添加手势识别器的示例:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.totalPowerPopUpView addGestureRecognizer:tapGestureRecognizer];
[self.co2PopUpView addGestureRecognizer:tapGestureRecognizer];
视图由按下UIButton触发的选择器显示(通常在设置自定义视图属性的if语句中有其他代码,但为了简单起见,我将其删去):

弹出视图存在,但当我点击它们时,不会调用手势识别器选择器。为什么不呢?

这是否有效:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]     initWithTarget:self action:@selector(hidePopUpView:)];
[self.totalPowerPopUpView addGestureRecognizer:tapGestureRecognizer];

tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.co2PopUpView addGestureRecognizer:tapGestureRecognizer];
这是否有效:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]     initWithTarget:self action:@selector(hidePopUpView:)];
[self.totalPowerPopUpView addGestureRecognizer:tapGestureRecognizer];

tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.co2PopUpView addGestureRecognizer:tapGestureRecognizer];

仔细检查并确保要将UIGestureRecognitor添加到的UIView已将
UserInteractionEnabled
设置为
YES
。i、 e


[self.imageView setUserInteractionEnabled:是]

仔细检查并确保要向其添加UIGestureRecognitor的UIView已将
UserInteractionEnabled
设置为
YES
。i、 e


[self.imageView setUserInteractionEnabled:是]

是的。我想我不能将手势识别器附加到多个视图上?没错。这是因为手势识别器将其附加到的视图作为属性,而不是视图列表,因此只能附加一个视图。@yuf在任何官方文档中都提到过吗?@skyline75489您的意思是说手势识别器只能附加到一个视图的文档?这听起来像是单数的暗示。@yuf,这是有道理的。谢谢你的回答。是的。我想我不能将手势识别器附加到多个视图上?没错。这是因为手势识别器将其附加到的视图作为属性,而不是视图列表,因此只能附加一个视图。@yuf在任何官方文档中都提到过吗?@skyline75489您的意思是说手势识别器只能附加到一个视图的文档?这听起来像是单数的暗示。@yuf,这是有道理的。谢谢你的回答。