当我们定义了多个手势得时候,就需要对收拾做一些区分,当然不区分,每个手势定义一个方法名也是可以的,就是麻烦,所以···
通常我们是给控件加tag值来区分的,当然,手势没有自带的tag属性,但是手势所属的view具有tag属性,
UITapGestureRecognizer *tapGeture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonJump:)];
tapGeture1.delegate = self;
[_bView1 addGestureRecognizer:tapGeture1];
UIView *tapView1 = [tapGeture1 view];
tapView1.tag = 151;
UITapGestureRecognizer *tapGeture3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonJump:)];
tapGeture3.delegate = self;
[_bView3 addGestureRecognizer:tapGeture3];
UIView *tapView3 = [tapGeture3 view];
tapView3.tag = 153;
手势方法中实现如下
- (void)buttonJump:(UITapGestureRecognizer *)tapGesture{
UITapGestureRecognizer *singleTap = (UITapGestureRecognizer *)tapGesture;
NSInteger index = singleTap.view.tag;
switch (index) {
case 151:{
ActivitySignUpViewController *actSignUpVC = [[ActivitySignUpViewController alloc]initWithNibName:@"ActivitySignUpViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:actSignUpVC animated:YES];
break;
}
default:
break;
}
}