0

レイヤーとそのサブレイヤーのアニメーションをチェーンしようとしています。ただし、私が抱えている問題は、アニメーションのサブレイヤーの位置のモデル更新が、スーパーレイヤーのアニメーション中に視覚的に明らかになることです。アニメーションをチェーンするために使用しているコードは次のとおりです。

// Superlayer. 
CFTimeInterval now = [self.artworkContainer.layer convertTime:CACurrentMediaTime() fromLayer:nil];
CABasicAnimation *slideDown = [CABasicAnimation animationWithKeyPath:@"position"];
slideDown.duration = SLIDE_DOWN_DURATION; //SLIDE_DOWN_DURATION;
slideDown.beginTime = now;
slideDown.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
slideDown.fromValue = [self.artworkContainer.layer valueForKey:@"position"];

CGPoint finalPointOfContainer = CGPointMake(self.artworkContainer.layer.position.x, self.artworkContainer.layer.position.y+verticalDistanceOfFirstFall);
slideDown.toValue = [NSValue valueWithCGPoint:finalPointOfContainer];
self.artworkContainer.layer.position = finalPointOfContainer;
[self.artworkContainer.layer addAnimation:slideDown forKey:@"position"];

// Sublayer 
CABasicAnimation *moveActualArtwork = [CABasicAnimation animationWithKeyPath:@"position"];
moveActualArtwork.duration = timeOfSecondFall;
moveActualArtwork.beginTime = now + SLIDE_DOWN_DURATION;
moveActualArtwork.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
moveActualArtwork.fromValue = [self.artWork.layer valueForKey:@"position"];

CGPoint finalPointOfArtwork = CGPointMake(self.artWork.layer.position.x, self.artWork.layer.position.y+verticalDistanceOfSecondFall);
moveActualArtwork.toValue = [NSValue valueWithCGPoint:finalPointOfArtwork];
self.artWork.layer.position = finalPointOfArtwork; // If this is commented out, the superlayer animation looks correct (of course this isn't a true fix because the sublayer snaps back to its original position without a model update). 

moveActualArtwork.delegate = self;
[self.artWork.layer addAnimation:moveActualArtwork forKey:@"position"];
4

1 に答える 1

0

質問を書いているときに答えを見つけました。2番目のアニメーションのfillModeプロパティを設定する必要がありました。moveActualArtwork.fillMode = kCAFillModeBackwards;

とをタイムライン上の位置と考えるとfromValuetoValue問題は、サブレイヤーがfromValueタイムライン上のスポットに到達する前に、モデルレイヤーから離れて位置を決定していたことでした。kCAFillModeBackwardsを使用することにより、fromValueが効果的に拡張され、その前のタイムラインがカバーされるため、iOSは、アニメーションが実際に開始される前に何をレンダリングするかを認識します。

45:31に、WWDC2011のビデオSession421-CoreAnimationEssentialsをレビューする答えを見つけました。

于 2012-10-16T02:31:47.207 に答える