Reputation: 17591
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 know what view happens gesture? views are n16 and n17
Upvotes: 3
Views: 3755
Reputation: 75396
Like this:
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer {
NSLog(@"SWIPE");
UIView *vw = [gestureRecognizer view]; // this is the view that generated the
// gesture - either n16 or n17
}
Upvotes: 1
Reputation: 4473
I am not sure if you can register the same UIGestureRecognizer instance to different views, but if you could, I think UIGestureRecognizer.view property is what you are looking for.
So, you should be able to do something like this. (again, I am not sure if you can attach different UIGestureRecognizer instance to different views...)
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
if(gestureRecognizer.view == n16)
{
// specific operation to n16
}
else if(gestureRecognizer.view == n17)
{
// specific operation to n17
}
}
Upvotes: 3