xXDraklordXx
xXDraklordXx

Reputation: 45

Get the current skew angle of an UIView

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

Answers (3)

MOHAMMED MINHAZ
MOHAMMED MINHAZ

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

skram
skram

Reputation: 5314

You can try something like this:

CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];

Upvotes: 1

Rok Jarc
Rok Jarc

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

Related Questions