1、使用imageview实现GIF小动画
//创建一个数组,数组中按顺序添加要播放的图片(图片为静态的图片)
NSMutableArray *imgArray = [NSMutableArray array];
for (int i=0; i<35; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"donghua_%02d",i]];
[imgArray addObject:image];
}
//把存有UIImage的数组赋给动画图片数组
_animationImgView.animationImages = imgArray;
//设置执行一次完整动画的时长
_animationImgView.animationDuration = 35*0.06;
//动画重复次数 (0为重复播放)
_animationImgView.animationRepeatCount = 1;
//开始播放动画
[_animationImgView startAnimating];
2、imageview一定角度旋转动画
self.static_lightImgView.image = [UIImage imageNamed:@"guang"];
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 1.0];
rotationAnimation.duration = 6;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1;
[self.static_lightImgView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
网友评论