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

Community
  • 1
  • 1
dumbfingers
  • 7,001
  • 5
  • 54
  • 80
  • Also http://stackoverflow.com/questions/14007983/scale-uiview-with-the-top-center-as-the-anchor-point/ – rob mayoff Feb 05 '13 at 19:13
  • @robmayoff thanks but I raised a different question to ask the rotation axis. =) – dumbfingers Feb 05 '13 at 23:28
  • Your post says “The problem is, since I've set the anchor point to (0, 0.5), the view also got moved as well, like the image shown below”. This is exactly the problem that is solved in those other posts. – rob mayoff Feb 06 '13 at 00:36
  • @robmayoff sorry I might not clearly state my question. I've now updated the question to make it clearly. thx =) – dumbfingers Feb 06 '13 at 10:51

2 Answers2

0

Looks like you need to adjust your position when you adjust the anchor point. See this previous post:

Changing my CALayer's anchorPoint moves the view

The link in that post is old, the new one is here: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimationBasics/CoreAnimationBasics.html#//apple_ref/doc/uid/TP40004514-CH2-SW3

Looks like the key sentence is under "Anchor Points Affect Geometric Manipulations" which is "The position property is always specified relative to the layer’s anchor point".

Community
  • 1
  • 1
0

I finally figured out why I "can't set the axis of rotation" in this animation:

After carefully check the returning value of bounds and size of the layer, I found it is because the method like viewWillAppear within which the app cannot retrieve the actual frame or bounds size (either height or width will return 0).

When I put the same animations code as stated in my question into methods like viewDidAppear or viewDidLoad, I can freely set anchorPoint to make either x or y as my animation's rotation axis.

dumbfingers
  • 7,001
  • 5
  • 54
  • 80