Reputation: 45
How can I get the current angle of a skewed image?
The code I use to skew it is:
CGAffineTransform t = CGAffineTransformMake(1.0, 0.0, tan(angle*(M_PI/480)), 1.0, 0.0, 0.0);
Upvotes: 2
Views: 905
Reputation: 21
Try this:
CGFloat radians = atan2f([self myview].transform.b, [self myview].transform.a);
With this you can get a current angle of any UIView
.
Keep Rocking... enjoy... :)
Upvotes: 1
Reputation: 5314
You can try something like this:
CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
Upvotes: 1
Reputation: 18875
Try this:
CGFloat skew_c = [(NSNumber *)[view valueForKeyPath:@"layer.transform.c"] floatValue];
Keypath is guesstimated, but should work. CGAffineTransformMake docs.
EDIT:
Looks like CGAffineTransform is translated into 4x4 CATransform3D
matrix.
transform
is property of CALayer
of CATransform3D
type.
That means you can acces m11
..m44
parameters with calls like:
CGFloat m11 = [(NSNumber *)[view valueForKeyPath:@"layer.transform.m11"] floatValue];
...
...
CGFloat m44 = [(NSNumber *)[view valueForKeyPath:@"layer.transform.m44"] floatValue];
You'd still need to do some calculations to get your skew factor. You can derive equation for your c_factor from this great answer.
Upvotes: 0