【发布时间】:2013-03-13 22:42:40
【问题描述】:
编辑:CAAnimationGroup 的附加代码,动画按顺序绘制,但我仍然遇到firstAnimation 在secondAnimation 启动后消失的问题,我在documentation 中注意到CAAnimationGroup 它说:
animations 属性中动画的removedOnCompletion 属性当前被忽略。
我该如何解决这个问题?
我正在尝试为同一层上的多个CAKeyFrameAnimation 对象设置动画,以便当firstAnimation 完成时,它绘制的路径在secondAnimation 启动时仍保留在屏幕上,因此最终结果是一张由两个对象的路径一起在屏幕上。
目前,如果我将两个动画对象(按顺序)放在同一个方法中并调用它,那么屏幕上只会绘制secondAnimation。如果我将它们拆分并按顺序调用它们,firstAnimation 会被绘制到屏幕上,然后在secondAnimation 启动时消失。动画本身就完全按照预期工作。
我尝试四处寻找CAAnimationGroup 的示例,因为它似乎正是我要寻找的,但从我看到的几个示例中,我并不清楚什么是继续,或者如何产生我正在寻找的效果,谁能告诉我如何顺序绘制两个动画并将结果保留在屏幕上?
这是我的图层、我的两个动画和我的组:
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.animationLayer.bounds;
pathLayer.bounds = pathRect;
pathLayer.geometryFlipped = YES;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 10.0f;
pathLayer.lineJoin = kCALineJoinBevel;
CAKeyframeAnimation *firstAnimation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
firstAnimation.beginTime = 0.0;
firstAnimation.duration = 4.0;
firstAnimation.removedOnCompletion = NO; //Is being ignored by CAAnimationGroup
firstAnimation.fillMode = kCAFillModeForwards;
firstAnimation.values = [NSArray arrayWithObjects:
(id)path0.CGPath,(id)path1.CGPath,
(id)path2.CGPath,(id)path3.CGPath,
(id)path4.CGPath,(id)path5.CGPath,nil];
firstAnimation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.21],
[NSNumber numberWithFloat:0.22],
[NSNumber numberWithFloat:0.63],
[NSNumber numberWithFloat:1.0], nil];
CAKeyframeAnimation *secondAnimation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
secondAnimation.beginTime = 4.0; //This should come directly after firstAnimation
secondAnimation.duration = 3.0;
secondAnimation.removedOnCompletion = NO; //Is being ignored by CAAnimationGroup
secondAnimation.fillMode = kCAFillModeForwards;
secondAnimation.values = [NSArray arrayWithObjects:
(id)path00.CGPath,(id)path01.CGPath,
(id)path02.CGPath,nil];
secondAnimation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0],nil];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:firstAnimation,secondAnimation,nil];
group.duration = 7.0; //The total time of the animations, don't know if redundant
group.delegate = self;
[self.pathLayer addAnimation:group forKey:@"path"];
【问题讨论】:
-
@Till 我尝试了问题中的建议,实际上它确实连续播放动画,但是当第二个动画开始时我仍在擦除第一个动画,所以仍然缺少一些东西。有什么想法吗?
标签: ios core-animation caanimation cakeyframeanimation cashapelayer