私は自分の結果を達成するための 1 つの方法を発見しました。それが最善の方法であるかどうかはわかりませんので、他のアイデアに感謝します。
layer1 と layer2 を同時に作成し、両方を view.layer に追加します。次に、layer1 をアニメートして、新しい位置、duration = 0.3 に移動します。layer2 では、移動 (beginTime = 0.3、duration = 0.3) と hidden 属性を使用した別のアニメーションで構成されるグループでアニメーション化します。後者のアニメーションでは、layer2 がすぐに非表示になり、beginTime = 0.3 で再表示されます。後者のアニメーションを実現するために、私は CAKeyFrameAnimation を使用しました。これは、このアニメーションが完全に非表示または完全に再表示されている必要があるためです。
これがコードです。実装に関する詳細を削除して簡略化したため、これはアプリ内の実際のコードではありません。エラーがある場合は申し訳ありません。
CALayer layer1 = [CALayer layer];
CALayer layer2 = [CALayer layer];
/*
* set attributes of the layers -- cut out of this example
*/
layer1.position = toPosition1; // positions when animation is complete
layer2.position = toPosition2;
[myView.layer addSublayer:layer1];
[myView.layer addSublayer:layer2];
// animate layer 1
CABasicAnimation* move1 = [CABasicAnimation animationWithKeyPath:@"position"];
move1.duration = 0.3;
move1.fromValue = fromPosition2;
[layer1 addAnimation:move1 forKey:nil];
// animate layer 2 with a group
CABasicAnimation* move2 = [CABasicAnimation animationWithKeyPath:@"position"];
move2.duration = 0.3;
move2.fromValue = fromPosition2;
move2.beginTime = 0.3;
CAKeyframeAnimation *show = [CAKeyframeAnimation animationWithKeyPath:@"hidden"];
show.values = [NSArray arrayWithObjects:[NSNumber numberWithBool:YES], [NSNumber numberWithBool:NO], [NSNumber numberWithBool:NO], nil];
// times are given as fractions of the duration time -- hidden for first 50% of 0.6 sec
show.keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];
show.calculationMode = kCAAnimationDiscrete;
show.duration = 0.6;
show.beginTime = 0;
CAAnimationGroup *grp = [CAAnimationGroup animation];
[grp setAnimations:[NSArray arrayWithObjects:move2, show, nil ]];
grp.duration = 0.6;
[layer2 addAnimation:grp forKey:nil];
私