tap gesture recognizer - which object was tapped?

前端 未结 12 1292
萌比男神i
萌比男神i 2020-12-29 17:47

I\'m new to gesture recognizers so maybe this question sounds silly: I\'m assigning tap gesture recognizers to a bunch of UIViews. In the method is it possible to find out w

12条回答
  •  Happy的楠姐
    2020-12-29 18:22

    Its been a year asking this question but still for someone.

    While declaring the UITapGestureRecognizer on a particular view assign the tag as

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandlerMethod:)];
    [yourGestureEnableView addGestureRecognizer:tapRecognizer];
    yourGestureEnableView.tag=2;
    

    and in your handler do like this

    -(void)gestureHandlerMethod:(UITapGestureRecognizer*)sender {
        if(sender.view.tag == 2) {
            // do something here
        }
    }
    

提交回复
热议问题