- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_momImageView= [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,50,50)];
_momImageView.center=self.view.center;
_momImageView.image= [UIImageimageNamed:@"icon_exercise"];
[self.viewaddSubview:_momImageView];
[selfstartAnimation];
}
-(void)startAnimation{
//开始动画
CABasicAnimation*momAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];
momAnimation.fromValue= [NSNumbernumberWithFloat:-0.3];
momAnimation.toValue= [NSNumbernumberWithFloat:0.3];
momAnimation.duration=0.5;
momAnimation.repeatCount=CGFLOAT_MAX;
momAnimation.autoreverses=YES;
momAnimation.delegate=self;
[_momImageView.layeraddAnimation:momAnimationforKey:@"animateLayer"];
}
//暂停动画,图片未复位
-(void)pauseLayer:(CALayer*)layer
{
CFTimeIntervalpausedTime = [layerconvertTime:CACurrentMediaTime()fromLayer:nil];
layer.speed=0.0;
layer.timeOffset= pausedTime;
}
//重新开始动画
-(void)resumeLayer:(CALayer*)layer{
CFTimeIntervalpausedTime = [layertimeOffset];
layer.speed=1.0;
layer.timeOffset=0.0;
layer.beginTime=0.0;
CFTimeIntervaltimeSincePause = [layerconvertTime:CACurrentMediaTime()fromLayer:nil] - pausedTime;
layer.beginTime= timeSincePause;
}