语音动画实现

1.声明
@property(strong,nonatomic)UIImageView *voiceImgV;

-(UIImageView *)voiceImgV{
    if ( _voiceImgV == nil) {
        _voiceImgV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
        [_voiceImgV setImage:[UIImage imageNamed:@"v_anim4"]];
        
    }
    return _voiceImgV;
}
2.在播放的时候添加到当前的tableview上
//用一个uiimageview 盖住原来的再添加动画效果
    CGRect  frame  = [cell.voiceButton convertRect:self.voiceImgV.bounds toView:self.tableview];
    CGRect finalFrame = CGRectMake(frame.origin.x + 10, frame.origin.y + 10, frame.size.width, frame.size.height);
    [self.voiceImgV setFrame:finalFrame];
    [self.tableview addSubview:self.voiceImgV];
    [self.voiceImgV startAnimating];
3.设置播放动画
- (void)voicePlayWithAnimateTime:(NSInteger )time{
    //设置帧动画的图片数组
    self.voiceImgV.animationImages = [NSArray arrayWithObjects:
                                      [UIImage imageNamed:@"v_anim2"],
                                      [UIImage imageNamed:@"v_anim3"],
                                      [UIImage imageNamed:@"v_anim4"],nil];
    //设置帧动画播放时长
    [self.voiceImgV setAnimationDuration:1.0];
    //设置帧动画播放次数
    [self.voiceImgV setAnimationRepeatCount:time + 0.5];
    //如果动画正在播放就不会继续播放下一个动画
    if (self.voiceImgV.isAnimating) {
        return;
    }
    else{
        [self.voiceImgV startAnimating];
    }
}

你可能感兴趣的:(iOS)