//开始动画
CABasicAnimation *momAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
momAnimation.fromValue = [NSNumber numberWithFloat:-0.3];
momAnimation.toValue = [NSNumber numberWithFloat:0.3];
momAnimation.duration = 0.5;
momAnimation.repeatCount = CGFLOAT_MAX;
momAnimation.autoreverses = YES;
momAnimation.delegate = self;
[_momImageView.layer addAnimation:momAnimation forKey:@"animateLayer"];
//暂停动画,图片未复位
-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
//重新开始动画
-(void)resumeLayer:(CALayer*)layer{
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
//移除动画,图片复位
[self.momImageView.layer removeAllAnimations];