【问题标题】:Strange behaviour of CALayerCALayer 的奇怪行为
【发布时间】:2010-12-30 09:40:06
【问题描述】:

Iv 使 CALayer 沿曲线移动。动画完成后,我将图层隐藏在 animationDidStop 委托中。假设我将图层的 frame.origin 设置为点 x。我为图层设置动画以从点 x 移动到点 y。一旦动画停止,我将图层设置为隐藏。然而,该层在被隐藏之前再次出现在点 x 处。为什么会这样?在动画到达点 y 时停止后,如何立即停止并隐藏图层?

-(void)doAnimation  
{  
UIImage *movingImage = [UIImage imageNamed:@"XYZ.png"];  
movingLayer = [CALayer layer];   
 movingLayer.contents = (id)movingImage.CGImage;  
 movingLayer.anchorPoint = CGPointZero;  
 movingLayer.frame = CGRectMake(700.0f, 50.0f, movingImage.size.width, movingImage.size.height);  
 [self.view.layer addSublayer:movingLayer];

UIBezierPath *customPath = [UIBezierPath bezierPath];  
[customPath moveToPoint:CGPointMake(700,50)];  
[customPath addQuadCurveToPoint:CGPointMake(550, 50) controlPoint:CGPointMake(630, 10)];  
[customPath addQuadCurveToPoint:CGPointMake(270, 33) controlPoint:CGPointMake(355, -10)];  
[customPath addQuadCurveToPoint:CGPointMake(120, 0) controlPoint:CGPointMake(190, 0)];   
[customPath addLineToPoint:CGPointMake(-20, 20)];  

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];  
 pathAnimation.duration = 6.5f;  
 pathAnimation.path = customPath.CGPath;  
 pathAnimation.calculationMode = kCAAnimationLinear;  
 pathAnimation.delegate=self;  
 [movingLayer addAnimation:pathAnimation forKey:@"movingAnimation"];

}


-(void)animationDidStop:(CAAnimation *)animID finished:(BOOL)didFinish  
{  
movingLayer.hidden=YES;  
}

【问题讨论】:

  • 你需要给出一些代码来解决这个问题。

标签: iphone ipad core-animation calayer


【解决方案1】:

当您开始动画时,您应该将图层的位置设置为目标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    相关资源
    最近更新 更多