On 9/7/12, Uli Kusterer <witness.of.teacht...@gmx.net> wrote: > On 06.09.2012, at 09:48, Eric Wing <ewmail...@gmail.com> wrote: >> I want the thing I'm rotating to stay centered relative to its >> original screen position, so when I resize the window, I need the view to >> not shift in absolute terms despite the fact that the window's origin >> (lower-left corner) will need to move. >> >> I'm looking for ideas on the best/easiest way of accomplishing this. > > Easiest way? Before you start the rotation, make the window larger, and > offset all views by the amount you made it larger. Do the rotation, then > make the window smaller again once you're done. You can remember the > difference in an ivar. Or just create your window larger to start with. It's > borderless and transparent, who would notice? > > Larger by how much? Well, any rotated point can extend outside the rectangle > of the view at most by the radius of the rotation. The radius extends past > the view's edges the most when it is horizontal or vertical. > > So that means calculate the distance between the center of your view and > each of its corners. (distance between two points is sqrt(pow(a.x -b.x,2) + > pow(a.y -b.y,2)), if I remember maths class correctly). Remember the largest > of these. Then calculate the distance between your view's center and its > edges (NSMaxX(box) -NSMidX(box) and NSMaxY(box) -NSMidY(box)). Again, > remember the largest. > > Now you know how far one of your corners can at most be from the center, and > how far your edges are right now. The difference between the two is how much > you have to make the window larger to see all of that view. >
Thanks for the replies. Right: Pythagorean Theorem. But I just discovered that setFrameCenterRotation has this weird wobbly behavior. It looks like it is simultaneously translating the object and rotating it. I'm guessing Apple is actually rotating along the bottom-left corner, but is shifting it while rotating so it kind of stays in the center. But the result is this very odd rotation. I'm not sure it actually fits in the hypotenuse. Sigh. I guess I can just make the window overly big, but I'm rethinking things now since the animation looks so bad. On 9/7/12, Graham Cox <graham....@bigpond.com> wrote: > > Or, much more simply, hypot( b.x - a.x, b.y - a.y ); Neat. I didn't realize that existed and was part of the C99 spec until I looked it up just now. Thanks, Eric -- Beginning iPhone Games Development http://playcontrol.net/iphonegamebook/ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com