iOS中UIImageView 添加UITapGestureRecognizer后传参

原文地址:http://blog.csdn.net/sevenquan/article/details/50436290

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 150,150, 150)];
    imageView.image = [UIImage imageNamed:@"11"];
    
    imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickEvent:)];
    [imageView addGestureRecognizer:singleTap];
    singleTap.view.tag = 22222;
   
    [views addSubview:imageView];

-(void)clickEvent:(id)sender
{
    UITapGestureRecognizer *tap = (UITapGestureRecognizer*)sender;
    
    UIView *views = (UIView*) tap.view;
    
    NSUInteger tag = views.tag;
    
    NSLog(@"-----tag-------------%lu",(unsigned long)tag);
}

转载请注明出处:http://blog.csdn.net/sevenquan

你可能感兴趣的:(iOS中UIImageView 添加UITapGestureRecognizer后传参)