• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rotating an object around the center of a view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: rotating an object around the center of a view (From: Erik Buck <email@hidden>)

  • Prev by Date: Re: Very strange NSImage loading problem
  • Next by Date: Re: rotating an object around the center of a view
  • Previous by thread: Re: rotating an object around the center of a view
  • Next by thread: Re: rotating an object around the center of a view
  • Index(es):
    • Date
    • Thread