IOS: UISwipeGestureRecognizer

I have this code:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)]; [recognizer setNumberOfTouchesRequired:1]; [n16 addGestureRecognizer:recognizer]; [n17 addGestureRecognizer:recognizer]; - (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{ NSLog(@"SWIPE"); } 

How can I find out what kind of gesture looks like? views - n16 and n17

+4
source share
2 answers

I'm not sure that you can register the same instance of UIGestureRecognizer for different views, but if you could, I think the UIGestureRecognizer.view property is what you are looking for.

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer

So you should do something like this. (again, I'm not sure if you can attach another instance of UIGestureRecognizer to different views ...)

 - (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{ if(gestureRecognizer.view == n16) { // specific operation to n16 } else if(gestureRecognizer.view == n17) { // specific operation to n17 } } 
+4
source

Like this:

 - (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer { NSLog(@"SWIPE"); UIView *vw = [gestureRecognizer view]; // this is the view that generated the // gesture - either n16 or n17 } 
+1
source

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


All Articles