Start animation
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"];
Pause animation, picture not reset
-(void) Pauselayer: (calayer*) layer
{
Cftimeinterval pausedtime = [Layer Converttime:cacurrentmediatime () Fromlayer:nil];
Layer.speed = 0.0;
Layer.timeoffset = Pausedtime;
}
Start the animation again
-(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;
}
Remove animation, picture reset
[Self.momImageView.layer removeallanimations];
How iOS makes a picture shake left and right