CABasicAnimation的当前值

时间:2014-09-02 03:59:22

标签: ios cabasicanimation

因此,我将圆圈的路径设置为动画(完美运行):

CGPoint center = CGPointMake([self bounds].size.width/2.0, [self bounds].size.height/2.0);

circle.path = [UIBezierPath bezierPathWithArcCenter:center
                                             radius:radius-13 startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS([self percentageToAngle:100]) clockwise:NO].CGPath;


circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor blackColor].CGColor;
circle.lineWidth = 27.0;

[self.layer addSublayer:circle];

float currentAngle = [(NSNumber *)[ sublayer valueForKeyPath:@"strokeEnd" ] floatValue];

CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

drawAnimation.duration            = 2.0;
drawAnimation.repeatCount         = 0.0;
drawAnimation.removedOnCompletion = NO;


drawAnimation.fromValue = [NSNumber numberWithFloat:0.0];
drawAnimation.toValue   = [NSNumber numberWithFloat:1.0];

drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

drawAnimation.delegate = self;
[drawAnimation setValue:kAnimationName forKey:kLayerName];
[circle addAnimation:drawAnimation forKey:kAnimationName];

如果我在游戏中途停止动画,我该如何获得它的当前值? fromValue和toValue之间的角度或仅是值?

1 个答案:

答案 0 :(得分:-2)

停止动画时尝试此操作。

float currentRad = [[[circle.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] floatValue];