给手势UITapGestureRecognizer添加"tag"标志

原文地址http://yul100887.blog.163.com/blog/static/2003361352012108701432/

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]);
}


你可能感兴趣的:(给手势UITapGestureRecognizer添加"tag"标志)