1

編集: の添付コードCAAnimationGroup、アニメーションは順次描画されますが、開始するとfirstAnimation消える問題がまだ発生しており、ドキュメントで次のように述べています:secondAnimationCAAnimationGroup

animations プロパティ内のアニメーションの removedOnCompletion プロパティは現在無視されます。

どうすればこれを回避できますか?


CAKeyFrameAnimation同じレイヤーで複数のオブジェクトをアニメーション化して、firstAnimation終了時に描画されたパスが開始されたときに画面に残るようにしようとしsecondAnimationているため、最終結果は画面上で両方のオブジェクトのパスから一緒に作成された画像になります。

現在、両方のアニメーション オブジェクトを (順番に) 同じメソッドに入れて呼び出すとsecondAnimation、画面にのみが描画されます。それらを分割して順番に呼び出すとfirstAnimation、画面に引き込まれ、起動すると消えsecondAnimationます。アニメーション自体は意図したとおりに機能します。

私が探しているもののように見えるCAAnimationGroupので、例を探してみましたが、私が見たいくつかの例から、何が起こっているのか、または私が探している効果をどのように生み出すのかは本当に明らかではありません.両方のアニメーションを連続して描画し、結果を画面に保持する方法を誰か教えてもらえますか?

これが私のレイヤー、2 つのアニメーション、および私のグループです。

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"];
4

1 に答える 1

0

Ok, so I've found a tentative hack to solve my problem, Till's comment worked great for pure serialization but the animations kept on disappearing so that does not work for my case at all.

The hack that I used was to create a separate layer for each animation instead of putting both animations on a single CAShapeLayer instance, and then specify the duration and keyTime for both animations according to a time controller so as to get 1) the sequence of times to be correct between animations and 2) the timing within each animation to be correct.

By using separate layers, removedOnComplete = NO works again since I'm not using CAAnimationGroup so my animations are persistent which is something I really need in my app.

I'm not going to immediately accept this answer though because this seems like a low-ball way to do something which should be more intuitive on iOS.

于 2013-03-15T15:59:25.083 に答える