1

I have a UIView on top of another view that's using a UITouchGesture. The problem is that the touch events are being recognised in most forward UIView as well as in the UIView in the background. I would like the touch events to only work on the back most view only.

hope that makes sense.

thanks for any help

4

3 回答 3

4
view.userInteractionEnabled = NO;

view being the most forward UIview.

Good luck!

于 2012-04-05T11:34:25.930 回答
3

我认为最好的方法是在视图中声明 UITouchGesture ,当您需要在视图中禁用触摸时,您可以禁用:

一个水龙头的例子:

在您的 .h 文件中声明它:

UITapGestureRecognizer* tap;

在你的 .m 文件中

tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[yourView addGestureRecognizer:tap];

当您需要禁用水龙头时,您可以简单:

[tap setEnable:NO];

或删除它:

[yourView removeGestureRecognizer:tap];

这样,当您需要启用/禁用时会更容易,也更容易管理您的触摸。

参考

于 2012-04-05T11:48:19.843 回答
1

检查是否[gesture view]等于[[self.view subviews] objectAtIndex:0]并执行任何操作。

于 2012-04-05T11:44:51.523 回答