Re: rotating an object around the center of a view
Re: rotating an object around the center of a view
- Subject: Re: rotating an object around the center of a view
- From: Ken Tozier <email@hidden>
- Date: Sun, 4 Mar 2007 14:22:04 -0500
Thanks all
Here's the simplest solution I could come up with
- (id) initWithFrame:(NSRect) frame
{
self = [super initWithFrame:frame];
if (self)
{
// init transforms and clock face
[self initTransforms];
[self initClockFace];
tick = 0;
timer = [NSTimer scheduledTimerWithTimeInterval: 1
target: self
selector: @selector(moveDial:)
userInfo: nil
repeats: YES];
}
return self;
}
- (void) initTransforms
{
NSSize size = [self bounds].size;
ox = size.width / 2;
oy = size.height / 2;
rotateTransform = [[NSAffineTransform transform] retain];
offsetTransform = [[NSAffineTransform transform] retain];
[rotateTransform rotateByDegrees: -6];
[offsetTransform translateXBy: ox yBy: oy];
}
- (void) moveDial:(NSTimer *) inTimer
{
// move dial to {0, 0}
[offsetTransform invert];
[dial transformUsingAffineTransform: offsetTransform];
// rotate it
[dial transformUsingAffineTransform: rotateTransform];
// move it back to {ox, oy}
[offsetTransform invert];
[dial transformUsingAffineTransform: offsetTransform];
tick++;
[self setNeedsDisplay: YES];
}
_______________________________________________
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:
This email sent to email@hidden