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;
}
答案 0 :(得分:0)
启动动画时,应将图层的位置设置为目的地。