iOS中UIImageView 添加UITapGestureRe

2017-10-10  本文已影响406人  薄凉_简书
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);
}
上一篇下一篇

猜你喜欢

热点阅读