views:

224

answers:

2

When changing the center point of an 10 degrees rotated view, the specified coordinates for the center point will not match the coordinate system of the superview.

As an example, when you want to go straight up by y - 50, and no horizontal movement (i.e. x = theRotatedView.center.x), the shift in y-direction will be rotated. The view will go up and right, and not just up.

The rotation is done on the view, not on the layer.

I could wrap it in a superview that does the movement, while the subview does the rotation. Then I had no problems with converting. But maybe there is some simple solution. I just want to move the center of an rotated view as if the view was not rotated, i.e. when wanting y to be decremented by 10, just do so without worrying about the rotated coordinates. Are there any methods or functions for converting between the coordinate systems, so that I can just specify the center point coordinates in superview coordinates and it will just be right when applying these to the rotated view's center property?

A: 

You can multiply your coordinates by a transformation matrix. This puts your coordinates into your parent view's "coordinate space". You can also use the inverse matrix of the parent view to take coordinates that are in the parent view and return them to "world space".

http://en.wikipedia.org/wiki/Rotation_matrix

Read further down the page for pseudo-code examples.

Soviut
+1  A: 

Look at the CGAffineTransform methods, such as CGAffineTransformMake, for an easier way to generate the transforms you need. You can combine rotation and translation in one matrix.

Kendall Helmstetter Gelner