关于手势 — 手势添加tag值

来源:互联网 发布:cmd登录mysql数据库 编辑:程序博客网 时间:2024/04/29 13:16

当我们定义了多个手势得时候,就需要对收拾做一些区分,当然不区分,每个手势定义一个方法名也是可以的,就是麻烦,所以···

通常我们是给控件加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;    }}

0 0
原创粉丝点击