美文网首页
添加自传动画

添加自传动画

作者: 木马不在转 | 来源:发表于2016-09-01 16:32 被阅读12次

    //添加动画

    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;

    }

    相关文章

      网友评论

          本文标题:添加自传动画

          本文链接:https://www.haomeiwen.com/subject/jrthettx.html