レイヤの位置をアニメーション化し、変換(回転)しました。アニメーションCALayer anchorPoint
今、anchorPointをアニメーションする必要がありましたが、すべての試みで失敗しました。私はこれを行う場合でも:
2012... App[6437:403] layer: 1, KeyPath: anchorPoint, fromValue: NSPoint: {1.05, 0.5}, toValue: NSPoint: {1.05, 0.5}, Duration: 2.5
これはのNSLogは...そして、私が得る結果は層がメーリングリストの行き過ぎX軸に左に移動します。..層をアニメーション戻ってくる前に立ち往生していると繰り返す(自動逆転がオンであるため)。
レイヤの階層に関する注意: SuperLayerには、アニメーションを適用する3つのサブレイヤがあります。
なぜですか?アンカーポイントはどのようにアニメーション化されるべきですか?
マイコード:
NSArray* subKeyPath = [keyPaths objectAtIndex:tag];
NSArray* subToValue = [toValues objectAtIndex:tag];
NSArray* subDuration = [durations objectAtIndex:tag];
NSEnumerator* keyPathsEnum = [subKeyPath objectEnumerator];
NSEnumerator* toValuesEnum = [subToValue objectEnumerator];
NSEnumerator* durationsEnum = [subDuration objectEnumerator];
NSString* keyPath;
NSNumber* toValue;
NSNumber* duration;
while ((keyPath = [keyPathsEnum nextObject]) && (toValue = [toValuesEnum nextObject]) && (duration = [durationsEnum nextObject])) {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:keyPath];
id offsetToValue;
if ([keyPath hasPrefix:@"position"]) {
//I removed the position animation, since animating the anchorPoint should suffice
} else if ([keyPath hasPrefix:@"anchorPoint"]) {
//This was when I used anchorPoint.x float value = [[subLayer valueForKeyPath:keyPath] floatValue] - ([toValue floatValue]/[[subLayer contents] size].width);
offsetToValue = [NSNumber valueWithPoint:CGPointMake(1.05, 0.5)];
keyPath = [keyPath substringToIndex:[keyPath length]-2];
} else {
offsetToValue = toValue;
}
...
animation.toValue = offsetToValue;
animation.duration = [duration floatValue];
animation.fillMode = kCAFillModeForwards;
animation.repeatCount = INFINITY;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[subLayer addAnimation:animation forKey:keyPath];
//update the model
}
私は「anchorPoint.x」キーパス、同じ結果をアニメーション化しようとした:(
最終ノート、私はココアのアプリを書いていますが、X値をアニメーション化することでなければなりません(私は最初からあなたと一緒に座っていますかのように)正確にココアとココアタッチの両方で同じ。
私はあなたのコード自体にコメントする場合、それは素敵な&クリーン –
おかげ@JamesGrahamです!私は主にそのような芸術の価値を見ていない開発者と協力しています:/ – Mazyod
それは読むのが楽しいです。 –