I want to rotate a view around the right edge of the screen, like a door opening. This is what I have so far:
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0f/500;
view.layer.transform = CATransform3DRotate(transform, kDegreesToRadians(90), 0, 1, 0);
[UIView animateWithDuration:2.0f animations:^{
view.layer.transform = transform;
} completion:nil];
I'm not totally solid on CATranforms yet or matrices for that matter so if someone could push me in the right direction, it'd be much appreciated!
UIView animations are for animating the properties of a view, not for animating layers. To the best of my knowledge, you can't animate a view's layer using a UIView animateWithDuration: call.
You'll need to create a CABasicAnimation and add it to your view's layer yourself.
It's been a while since I've done CAAnimations, but let's see what I can dig up:
As atxe says, you should move the layer's anchor point to 1,.5 before doing this animation, so it rotates around the right edge.
Here is some code from our "Kevin & Kell" cartoon app, that does an animation of a door swinging open on it's hinge:
The transform logic is all but identical to yours (I use an m34 value of -1/100 for a more exaggerated 3D effect. Your -1/500 setting is more normal.)
Note that instead of trying to do the animation from a UIView animation block, I create a CABasicAnimation, and set it's fromValue and toValue properties to the starting and ending transform values.
You should be able to use this code as a starting-point for your animation.