旋转加载动画
1.自定义UIImageView
UIImageView *loadingImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.width/2-15, self.height/2-15, 31, 31)];
loadingImage.image = [UIImage imageNamed:@"icon_video_loading"];
loadingImage.userInteractionEnabled = YES;
[self addSubview:self.loadingImage];
2.开始动画
-(void)showPlayLoading{
if (![self.loadingImage.layer animationForKey:@"loading"]) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: M_PI *2];
animation.duration=3;
animation.autoreverses=NO;
animation.fillMode = kCAFillModeForwards;
animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多少次
[self.loadingImage.layeraddAnimation:animationforKey:@"loading"];
}
}
3.结束动画(合适的位置结束加载动画)
-(void)stopPlayLoading{
[self.loadingImage.layer removeAnimationForKey:@"loading"];
self.loadingImage.hidden = YES;
}