开发者

Gesture recognizer on button

开发者 https://www.devze.com 2023-03-08 06:45 出处:网络
I\'d like to implement a gesture recognizer (swipe action) for a button. The problem is, the buttons are create programmatically and are or aren\'t existent based on a few conditions. So, I don\'t kno

I'd like to implement a gesture recognizer (swipe action) for a button. The problem is, the buttons are create programmatically and are or aren't existent based on a few conditions. So, I don't 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's tag
    }
}

Of course, the if-statement should return Yes when any button view is pressed...

Anyone ha开发者_JAVA技巧s any idea on what the word aButtonView should be? Or if it's even possible? Thanks in advance.


You should think about using UISwipeGestureRecognizer instances. Attach the gesture recognizer to the 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]] ) {

0

精彩评论

暂无评论...
验证码 换一张
取 消