I have an overlay view (Which has self-drawn shapes) that I display over an ImageView. I want the view to be movable, resizable, and rotatable. I could allow the user to move the overlay by dragging it from the middle, or resize it by dragging it from one of two sides (right or bottom). What I still could not do is to allow the user to rotate it by moving the left-top edge.
myView.transform = CGAffineTransformMakeRotation(angle * M_PI / 180);
But how can I calculate the angle based on user touches? Any ideas?
The easiest way is to use a
UIRotationGestureRecognizerwhich gives you the rotation value as a property.If you can’t use a gesture recognizer, try something like this (untested):
See Wikipedia or do a Google search to learn more about polar coordinates and how to convert between cartesian and polar coordinate systems.