美文网首页
iOS中UIImageView 添加UITapGestureRe

iOS中UIImageView 添加UITapGestureRe

作者: 薄凉_简书 | 来源:发表于2017-10-10 13:56 被阅读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);
    }
    

    相关文章

      网友评论

          本文标题:iOS中UIImageView 添加UITapGestureRe

          本文链接:https://www.haomeiwen.com/subject/wxmvyxtx.html