Ios 排队时出现故障

Ios 排队时出现故障,ios,animation,visual-glitch,Ios,Animation,Visual Glitch,我有一个CAShapeLayer,在那里我制作了一个圆的动画。动画是先顺时针“取消绘制”圆,然后顺时针重新绘制圆。有点像一个“旋转的圆圈”。另一种方法是:将路径笔划终点移动到起点,然后将起点移动到终点 动画本身可以工作,但有时会产生小故障。当它被认为是“未绘制的”时,它表现在对整个圆圈的短暂一瞥中 为什么会发生这种情况?您如何解决它 谢谢 // Shape creation layer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMak

我有一个CAShapeLayer,在那里我制作了一个圆的动画。动画是先顺时针“取消绘制”圆,然后顺时针重新绘制圆。有点像一个“旋转的圆圈”。另一种方法是:将路径笔划终点移动到起点,然后将起点移动到终点

动画本身可以工作,但有时会产生小故障。当它被认为是“未绘制的”时,它表现在对整个圆圈的短暂一瞥中

为什么会发生这种情况?您如何解决它

谢谢

// Shape creation
layer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.width - 2 * OUTER_BORDER_WIDTH, self.width - 2* OUTER_BORDER_WIDTH)].CGPath;

// Animation queuing
-(void) applyNextAnimation
{

    CABasicAnimation* animation;

    if (self.animatingOpening)
    {
        animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        animation.fromValue = [NSNumber numberWithFloat:0.0f];
        animation.toValue = [NSNumber numberWithFloat:1.0f];
        self.animatingOpening = NO;
    }
    else
    {
    animation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
        animation.fromValue = [NSNumber numberWithFloat:0.0f];
        animation.toValue = [NSNumber numberWithFloat:1.0f];
        self.animatingOpening = YES;
    }

    animation.duration = 1.0f;
    animation.autoreverses = NO;
    animation.delegate = self;
    animation.removedOnCompletion = YES;
    [self.outerCircleLayer addAnimation:animation forKey:@"stroke"];
}

// Animation stop callback
-(void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    if (self.isAnimating)
    {
        [self applyNextAnimation];
    }
}

它会闪烁,因为您没有在图层上设置相应的特性。因此,当动画完成时,层的模型仍处于预先设置动画的状态,这就是您在两个动画之间瞬间看到的

这会让你实现你想要的

if (self.animatingOpening)
{

    self.outerCircleLayer.strokeStart = 0.0;

    animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    animation.fromValue = [NSNumber numberWithFloat:0.0f];
    animation.toValue = [NSNumber numberWithFloat:1.0f];
    self.animatingOpening = NO;
}
else
{
    self.outerCircleLayer.strokeStart = 1.0;

    animation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
    animation.fromValue = [NSNumber numberWithFloat:0.0f];
    animation.toValue = [NSNumber numberWithFloat:1.0f];
    self.animatingOpening = YES;
}

animation.duration = 1.0f;
animation.autoreverses = NO;
这几乎是可行的,但是当您从未绘制状态过渡到开始为绘制状态设置动画时,您会注意到一个更微妙的问题。圆的起点在开始时有一个小的反向动画。这是一个通过将strokeStart从1.0设置为0.0触发的隐式动画:您需要删除它,以便所有动画效果都在您的控制之下。您只需在CATTransaction上将disableActions设置为YES即可实现这一点:

[CATransaction setDisableActions:YES];

(将其添加到
if(self.animatingOpening)

非常好!我添加了
[CATransaction setDisableActions:NO]以保留此处未显示的动画。(另一层)很高兴它有用。我看到您正在处理一些涉及高频传感器数据存储的有趣问题,因此我为您的另一个问题添加了一些想法。。