iOS: issues with UIGestureRecognisers vs Subviews

送分小仙女□ 提交于 2019-12-10 22:34:58

问题


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];

I noticed two issues!

  1. 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?

  2. 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.

Thanks.


回答1:


UIGestureRecognizers can only be attached to one view at a time. You will have to create a separate one for each image view.



来源:https://stackoverflow.com/questions/9994850/ios-issues-with-uigesturerecognisers-vs-subviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!