Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rotating an object around the center of a view



I've just written a Clock View myself and came up against the same problem. Theoretically since NSAffineTransform is just a mathematical transformation matrix so it is possible - but I couldn't find a way to do it. Not knowing the internals of the class it might involve subclassing to use a 3x3 matrix.

I solved it instead by constructing the clock face and hands about the origin using NSAffineTransform as usual to rotate the various parts correctly. Then I used another affine transform to move the bezier paths into the centre of the view.

There's an example project in your /Developer/Examples/AppKit/ ClockControl folder that you may find useful, I used the equations that calculate how many degrees to rotate by from this project as the basis for mine.

Also something to bear in mind is that the NSAffineTransform rotate methods rotate anti-clockwise when passed a positive value (this is due to the way that the transformation matrix is setup), pass them a negative value to perform clockwise rotation.

- Keith


On 4 Mar 2007, at 10:07, Ken Tozier wrote:

Hi

I'm writing a clock class and am having some trouble getting the hands to rotate around the center of the view using an NSAffineTransform. As it stands now, it's rotating the hands around the lower left corner of the view. Is there any way to set the draw origin of the view to the center without moving the view itself?

Alternately, is there a way to define a transform so that it rotates from a specified point rather than the lower left corner?

Thanks

Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >rotating an object around the center of a view (From: Ken Tozier <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.