次のコードを使用して、アニメーション化しているビューのレイヤーとプレゼンテーションレイヤーの境界の前後の状態をダンプしています。何の変化も見られません-私の理解の点で何かが欠けているようです-すでにCAプログラミングガイドを数回読んでいますが、役に立ちません。任意のガイダンスをいただければ幸いです
- (void) shrink{
[Dumper dumpRect:@"BEFORE layer bounds" :[iv.layer bounds]];
[Dumper dumpRect:@"BEFORE p-layer bounds" :[iv.layer.presentationLayer bounds]];
[UIView animateWithDuration:1.5 animations:^{
CABasicAnimation *scaleAnim = [CABasicAnimatianimationWithKeyPath:@"transform.scale"];
scaleAnim.fromValue = [NSNumber numberWithFloat:1];
scaleAnim.toValue = [NSNumber numberWithFloat:0.5];
scaleAnim.autoreverses=NO;
[scaleAnim setDuration:1];
// these need to be invoked to retain the scaled version
scaleAnim.removedOnCompletion = NO;
[scaleAnim setFillMode:kCAFillModeForwards];
[iv.layer addAnimation:scaleAnim forKey:@"scale"];
}completion:^(BOOL finished){
NSLog(@"Animation done - %d",finished);
[Dumper dumpRect:@"AFTER layer bounds" :[iv.layer bounds]];
[Dumper dumpRect:@"AFTER p-layer bounds" :[iv.layer.presentationLayer bounds]];
}];
}
このコードを実行すると、次のようになります。 BEFORE layer bounds - Rect x=0.000000 y=0.000000 w=100.000000 h=200.000000 BEFORE p-layer bounds - Rect x=0.000000 y=0.000000 w=100.000000 h=200.000000 Animation done - 1 AFTER レイヤー境界 - Rect x=0.000000 y=0.000000 w=100.000000 h=200.000000 AFTER p レイヤー境界 - Rect x=0.000000 y=0.000000 w=100.000000 h=200.000000
前後で変化なし?
「transform.translation」変換を使用しても、同じ動作を観察しています。
UIView 、つまり iv を適切なフレーム値で設定できるように、最終的な境界が必要です。
関連する質問は次のとおりです-レイヤーがアニメーション化されている場合、描画は行われますが、基になるビューは元のフレームで設定されていることを理解しています.UIViewフレームを設定する正しい方法は何ですか.