2

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);
xXDraklordXx
  • 45
  • 1
  • 7

3 Answers3

1

You can try something like this:

CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
skram
  • 5,314
  • 1
  • 22
  • 26
1

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... :)

Steve Westbrook
  • 1,698
  • 2
  • 20
  • 21
0

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.

Community
  • 1
  • 1
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • I don't understand how to do it yet =( – xXDraklordXx Jun 10 '12 at 19:40
  • I'm also trying to figure it out. The problem is that the parameters you give to `CGAffineTransformMake` are translated to a different kind of matrix so you can't get them back by simply reading them. [3D projection - Wiki](http://en.wikipedia.org/wiki/3D_projection#Perspective_projection) is also helpfull but quite complex. – Rok Jarc Jun 10 '12 at 19:43
  • Here's a document that seems very promising:[Matrices, Quartz 2D, CGAffineTransform, CATransform3D](http://www.odysseyinc.com/downloads/EnterTheMatrix.pdf) – Rok Jarc Jun 10 '12 at 19:57
  • 1
    I've solved it creating a custom UIView and adding a skewAngle property to it. – xXDraklordXx Jun 10 '12 at 20:39
  • Congratulations, simplest solution is usually the best one :) – Rok Jarc Jun 10 '12 at 20:47