當我們定義了多個手勢得時候,就需要對收拾做一些區分,當然不區分,每個手勢定義一個方法名也是可以的,就是麻煩,所以···
通常我們是給控件加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;
}
}