1

In a nutshell, I intend to rotate a full screen size of view (bound size: 320,460) alongside it's y-axis(left edge).

I have achieved rotation via CAAnimation by using the code below:

CATransform3D transform = CATransform3DMakeRotation(M_PI_2, 0, 1, 0);
CGPoint origPoint = self.view.center;

//Set anchor Point
self.view.layer.anchorPoint = CGPointMake(0, 0.5);
//Set center point
[self.view setCenter: origPoint];

transform.m34 = 1.0/8000.0;
transform.m14 = -0.0015; 
CABasicAnimation *animRotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
[animRotate setFromValue:[NSValue valueWithCATransform3D:transform]];
[animRotate setDuration:4.0];
[self.view.layer addAnimation:animRotate forKey:nil];

So my question is: How can I set the rotation axis as the left edge of this view?

Many thanks.

I took reference about anchor point via this useful blog

4

2 に答える 2

0

アンカーポイントを調整するときは、位置を調整する必要があるようです。この以前の投稿を参照してください。

CALayer の anchorPoint を変更すると、ビューが移動します

その投稿のリンクは古いですが、新しいリンクはこちらです: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimationBasics/CoreAnimationBasics.html#//apple_ref/doc/uid /TP40004514-CH2-SW3

キーセンテンスは、「アンカーポイントは幾何学的操作に影響を与える」の下にあるように見えます。これは、「位置プロパティは常にレイヤーのアンカーポイントに対して相対的に指定されます」です。

于 2013-02-05T19:07:46.657 に答える
0

このアニメーションで「回転軸を設定できない」理由がようやくわかりました。

viewWillAppear境界の戻り値とレイヤーのサイズを注意深く確認した後、アプリが実際のフレームまたは境界のサイズを取得できない (高さまたは幅のいずれかが 0 を返す)ようなメソッドが原因であることがわかりました。

viewDidAppear質問と同じアニメーションコードをまたはのようなメソッドに入れると、アニメーションの回転軸として x または y をviewDidLoad自由に設定できます。anchorPoint

于 2013-02-12T10:31:58.407 に答える