美文网首页
iOS 如何处理多个UIImageView点击事件

iOS 如何处理多个UIImageView点击事件

作者: 小辉辉___ | 来源:发表于2017-01-17 20:28 被阅读145次
    for (int i = 0; i < 5; i++) {
      //语音动画
      UIImageView* recordAnimImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];
      recordAnimImage.image = [UIImage imageNamed:@"voice_dynamic3-1"];
      UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(commentImageRecordClick:)];
      recordAnimImage.tag = recordTag;
      recordAnimImage.userInteractionEnabled = YES;
      [recordAnimImage addGestureRecognizer:labelTapGestureRecognizer];
      [self.contentView addSubview:recordAnimImage];
    }
    
    //点击事件
    -(void)commentImageRecordClick:(UITapGestureRecognizer*)recognizer
    {
      //重点代码,判断点击的是哪一个imageView
      UIImageView *recordAnimImage = (UIImageView *)recognizer.view;
      recordAnimImage.animationImages = [NSArray arrayWithObjects:
      [UIImage imageNamed:@"voice_dynamic1-1"],
      [UIImage imageNamed:@"voice_dynamic2-1"],
      [UIImage imageNamed:@"voice_dynamic3-1"],nil];
      recordAnimImage.animationDuration = 1;
      recordAnimImage.userInteractionEnabled = NO;
      recordAnimImage.animationRepeatCount = 3;
      [recordAnimImage startAnimating];
    }
    

    相关文章

      网友评论

          本文标题:iOS 如何处理多个UIImageView点击事件

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