Button Gesture Recognizer

I would like to implement a gesture recognizer (swipe action) for a button. The problem is that buttons are created programmatically and exist or do not exist based on several conditions. So, I do not know if there are buttons or how many.

I know I need something like:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if (touch.view == aButtonView) {
        //get the button tag
    }
}

Of course, the if-statement should return Yes when you click any kind of button ...

Does anyone have an idea of ​​what a word should mean aButtonView? Or if it is possible? Thanks in advance.

+3
source share
1 answer

You should consider using instances UISwipeGestureRecognizer. Attach gesture recognizer to button objects -

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                            action:@selector(handleSwipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[button addGestureRecognizer:swipe];
[swipe release];

and in handleSwipe:

- (void) handleSwipe:(UISwipeGestureRecognizer *)swipe {
    NSInteger tag = swipe.view.tag;
}


it should be if ( [gestureRecognizer.view isKindOfClass:[UIButton class]] ) {
+8
source

All Articles