I am applying an rotation transform animation in an animation block with this transform:
CATransform3D rotatedTransform = self.layer.transform;
rotatedTransf
Try this:
CGFloat setAngle = 75.0;
CATransform3D t = CATransform3DIdentity;
t.m34 = 0.004;
t = CATransform3DRotate(t, -M_PI/180*setAngle, 0, 1, 0);
self.testView.layer.transform = t;
CGFloat getAngle = 0;
if (t.m11 < 0.0f) {
getAngle = 180.0f - (asin(t.m13) * 180.0f / M_PI);
} else {
getAngle = asin(t.m13) * 180.0f / M_PI;
}
NSLog(@"setAngle=%@ getAngle=%@", @(setAngle), @(getAngle));
You can retrieve the current state of an animating layer by grabbing its presentationLayer. Assuming that you have not applied any other transformations to the layer, you can extract the current angle of the rotating layer using code like the following:
CATransform3D rotationTransform = [(CALayer *)[self.layer presentationLayer] transform];
float angle;
if (rotationTransform.m11 < 0.0f)
angle = 180.0f - (asin(rotationTransform.m12) * 180.0f / M_PI);
else
angle = asin(rotationTransform.m12) * 180.0f / M_PI;
In an otherwise unmodified transform, the m11 and m12 values are coordinates that lie on the unit circle, so you can use trigonometry to determine the angle they describe.
EDIT (5/18/2009): Added a typecast to CALayer to overcome compiler warnings and fixed the naming of the transform in the trigonometry operations.
This is an old question but I came across this answer while trying to find the current rotation angle during a key frame animation:-
CALayer* layer = [self.layer presentationLayer];
float currentAngle = [[layer valueForKeyPath:@"transform.rotation.z"] floatValue];
Seems to work for me. Also, nice and concise.