//添加动画
CABasicAnimation *monkeyAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
monkeyAnimation.toValue = [NSNumber numberWithFloat:2.0 *M_PI];
monkeyAnimation.duration = 1.5f;
monkeyAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
monkeyAnimation.cumulative = NO;
monkeyAnimation.removedOnCompletion = NO; //No Remove
monkeyAnimation.repeatCount = FLT_MAX;
[self.backimageView.layer addAnimation:monkeyAnimation forKey:@"AnimatedKey"];
// 加载动画 但不播放动画
self.backimageView.layer.speed = 0.0;
- (void) startAnimation
{
self.backimageView.layer.speed = 1.0;
self.backimageView.layer.beginTime = 0.0;
CFTimeInterval pausedTime = [self.backimageView.layer timeOffset];
CFTimeInterval timeSincePause = [self.backimageView.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
self.backimageView.layer.beginTime = timeSincePause;
}
- (void)stopAnimation
{
CFTimeInterval pausedTime = [self.backimageView.layer convertTime:CACurrentMediaTime() fromLayer:nil];
self.backimageView.layer.speed = 0.0;
self.backimageView.layer.timeOffset = pausedTime;
}
网友评论