UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.image = [UIImage imageNamed:@"xxx"];
imageView.userInteractionEnabled = YES;
[self.view addSubview:imageView];
//如果设置tag,需要先addGestureRecognizer,再设置view.tag
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickEvent:)];
[imageView addGestureRecognizer: tap];
tap.view.tag = 2017;
- (void)clickEvent:(UITapGestureRecognizer *)tap
{
NSLog(@"view.tag = %ld",tap.view.tag);
}
网友评论