iOS:UIGestureRecognisers与Subviews的问题

时间:2012-04-03 13:59:06

标签: ios ipad uiimageview uigesturerecognizer subviews

我编写了以下代码,将手势识别器附加到多个图像视图中。

[imageview1 setUserInteractionEnabled:YES];
[imageview1 setMultipleTouchEnabled:YES];

[imageview2 setUserInteractionEnabled:YES];
[imageview2 setMultipleTouchEnabled:YES];

[imageview3 setUserInteractionEnabled:YES];
[imageview3 setMultipleTouchEnabled:YES];

[imageview4 setUserInteractionEnabled:YES];
[imageview4 setMultipleTouchEnabled:YES];

[imageview5 setUserInteractionEnabled:YES];
[imageview5 setMultipleTouchEnabled:YES];

[imageview6 setUserInteractionEnabled:YES];
[imageview6 setMultipleTouchEnabled:YES];

UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)];
gestureRecognizer.delegate = self;
[imageview1 addGestureRecognizer:gestureRecognizer];
[imageview2 addGestureRecognizer:gestureRecognizer];
[imageview3 addGestureRecognizer:gestureRecognizer];
[imageview4 addGestureRecognizer:gestureRecognizer];
[imageview5 addGestureRecognizer:gestureRecognizer];
[imageview6 addGestureRecognizer:gestureRecognizer];

我发现了两个问题!

  1. 所有imageview都没有附加手势识别器!只有一个imageview6(最后一个附加)具有手势识别器。这是苹果不允许的吗?

  2. 我在父视图的子视图中拥有所有这些图像视图。当我将这些直接添加到父视图(self.view)时,它可以工作,但问题仍然是#1。当我在子视图(self.view.mysubview)中有这些图像视图时,他们都没有识别出手势!

  3. 请有人请告诉我如何处理这些问题。

    感谢。

1 个答案:

答案 0 :(得分:6)

UIGestureRecognizer一次只能附加到一个视图。您必须为每个图像视图创建一个单独的图像。