iOS:UIGestureRecognisers与Subviews的问题 [英] iOS: issues with UIGestureRecognisers vs Subviews
问题描述
我编写了以下代码,将手势识别器附加到多个图像视图。
I have written following code to attach gesture recogniser to multiple imageviews.
[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];
我注意到两个问题!
-
所有imageview都没有附加手势识别器!只有一个imageview6(最后附加)具有手势识别器。这是苹果不允许的吗?
All imageview doens't have gesture recogniser attached! Only one imageview6(the last attached) has the gesture recogniser. Is this something apple doesn't allow?
我在父视图的子视图中拥有所有这些图像视图。当我将这些直接添加到父视图(self.view)时,它可以工作,但问题仍然是#1。当我在子视图(self.view.mysubview)中有这些图像视图时,他们都没有识别出手势!
I have all these imageviews in subview of parent view. When I add these directly to parent view (self.view), it works but still issue#1 remains. When I have these imageviews in subview (self.view.mysubview), none of them recognise the gestures!
可能有人请告诉我如何处理这些问题。
Could someone please tell me how to deal with these issues please.
谢谢。
推荐答案
UIGestureRecognizer
一次只能附加到一个视图。您必须为每个图像视图创建一个单独的图像。
UIGestureRecognizer
s can only be attached to one view at a time. You will have to create a separate one for each image view.
这篇关于iOS:UIGestureRecognisers与Subviews的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!