Reputation: 987
I am rotating an NSView using:
setFrameRotation:
Which rotates the view around its bottom left corner. What is the best way to rotate a view around its center point?
Also, i want to get the points in the superview of its corners. Using:
view.frame.origin
Just gives me the corner before i rotate it. How would i get the actual points of its corners once it has been rotated?
Thanks in advance, Ben
Upvotes: 0
Views: 996
Reputation: 90541
To get an effective rotation about the center of the frame, you have to translate the frame's origin.
Also, of course view.frame.origin
gives the origin before you rotate it. It's also giving you the origin after you rotate it, because the rotation is around the origin. The origin isn't moving. If you do translate the origin to get rotation around the center, you'll then know the new origin.
To get the other corners, you'd use [view convertPoint:pt toView:view.superview]
, where pt
is each of the corners in the view's coordinate system. E.g. NSMakePoint(NSMaxX([view bounds]), NSMinY([view bounds]))
.
You can actually use this technique to obtain the translation you want. Compute the desired center of the view, or just record the current center if it's where you want it. Then rotate the view. Obtain the new location of the center using -convertPoint:toView:
. Then translate the origin by the difference between the new center and the desired center.
Upvotes: 1