Set an exclusive touch on multiple UIViews of the same class

I create a random number of custom UIViews of the same class, and I add them to the UIViewController view. I assign them a UITapGestureRecognizer, but I seem to be unable to make an exclusive contact:

for (int i = 0; i <= n; i++) { ICCatalogProductView *catalogProductView; catalogProductView = [[ICCatalogProductView alloc] init]; [self.view addSubview:catalogProductView] UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(testTouch)]; [catalogProductView addGestureRecognizer:tapGesture]; [catalogProductView setExclusiveTouch:YES]; } 

If I press UIViews at the same time, the method is called twice (not what I want). Is there any elegant way to solve this or any method in general?

+6
source share
1 answer

From the Apple documentation:

exclusiveTouch only prevents other species from entering during which they actively touch the exclusive touch screen. That is, if you put your finger in an exclusive touch form, the touches will not begin in other views until you lift the first finger. This does not prevent affecting from the start in other views, unless currently there are touches in the exclusiveTouch view.

To really make this view the only thing you can see on the screen, you will need to add one more view on top of everything else to catch the remaining strokes or subclass, somewhere in your hierarchy (or UIWindow itself) and override hitTest: withEvent: always return a text view, when it is visible, or return zero for touches not in your text view.

means that it has a single meaning, set exclusively in your one view, and not if you touch something outside of your view.

+1
source

Source: https://habr.com/ru/post/950258/


All Articles