Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 圆段的笔划动画以完整笔划结束_Objective C_Ios_Cocoa Touch_Core Animation_Cabasicanimation - Fatal编程技术网

Objective c 圆段的笔划动画以完整笔划结束

Objective c 圆段的笔划动画以完整笔划结束,objective-c,ios,cocoa-touch,core-animation,cabasicanimation,Objective C,Ios,Cocoa Touch,Core Animation,Cabasicanimation,我正在尝试为圆的一段的外观设置动画。为了存档这个,我使用了一个工作安静良好的CABASICANIONS 动画从顶部开始,安静地移动到整个圆的三分之一。但是,当动画完成时,将立即完全绘制圆 我怎样才能防止呢 以下是我的自定义UIView的源代码: - (void)drawRect:(CGRect)rect { int radius = 100; int strokeWidth = 10; CGColorRef color = [UIColor redColor].CGCol

我正在尝试为圆的一段的外观设置动画。为了存档这个,我使用了一个工作安静良好的CABASICANIONS

动画从顶部开始,安静地移动到整个圆的三分之一。但是,当动画完成时,将立即完全绘制圆

我怎样才能防止呢

以下是我的自定义UIView的源代码:

- (void)drawRect:(CGRect)rect
{
    int radius = 100;
    int strokeWidth = 10;
    CGColorRef color = [UIColor redColor].CGColor;
    int timeInSeconds = 5;

    CGFloat startAngle = 0;
    CGFloat endAngle = 0.33;

    CAShapeLayer *circle = [CAShapeLayer layer];

    circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;

    circle.position = CGPointMake(CGRectGetMidX(self.frame)-radius, CGRectGetMidY(self.frame)-radius);

    circle.fillColor = [UIColor clearColor].CGColor;
    circle.strokeColor = color;
    circle.lineWidth = strokeWidth;

    [self.layer addSublayer:circle];

    CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = timeInSeconds;
    drawAnimation.repeatCount         = 1.0;
    drawAnimation.removedOnCompletion = NO;

    drawAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
    drawAnimation.toValue   = [NSNumber numberWithFloat:endAngle];

    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
}

将动画应用于层时,“核心动画”将创建层的副本并为副本的特性设置动画。原始层称为模型层,副本称为表示层。动画从不更改模型层的特性

您试图通过将
removedOnCompletion
设置为
NO
来解决此问题。您还必须设置动画的
fillMode
,才能使其生效,但这并不是设置属性动画的正确方法

正确的方法是更改模型层上的特性,然后应用动画

// Change the model layer's property first.
circle.strokeEnd = endAngle;

// Then apply the animation.
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration            = timeInSeconds;
drawAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
drawAnimation.toValue   = [NSNumber numberWithFloat:endAngle];
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
这在from中进行了解释。我强烈建议您观看。

drawAnimation.duration期间,您对进度(0到1)有什么想法吗?