给UITapGestureRecognizer添加tag

UITapGestureRecognizer是没有tag属性,但他有UIView的属性,我们可以通过给UIView添加tag属性,从而标记UITapGestureRecognizer。

UITapGestureRecognizer *singleTap =
        [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(whenClickImage:)];
        [_firstImage addGestureRecognizer:singleTap];
        UIView *singleTapView = [singleTap view];
        singleTapView.tag = 0;
        [singleTap release];

-(void)whenClickImage:(id)sender
{
    UITapGestureRecognizer *singleTap = (UITapGestureRecognizer *)sender;
    NSLog(@"%d",[singleTap view].tag]);
}

posted on 2015-07-14 10:04  公羊华宇  阅读(266)  评论(0编辑  收藏  举报