• 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: Bob Smith <email@hidden>
  • Date: Sun, 4 Mar 2007 16:01:32 -0800


On Mar 4, 2007, at 12:01 PM, Ken Tozier wrote:


On Mar 4, 2007, at 2:59 PM, Erik Buck wrote:

Your solution seems workable but very strange to me.

Why rotate the "dial" instead of rotating the coordinate system in which the dial is drawn ?

Because the clock face and all it's parts are rendered in the same view. If I rotate the view coordinates, the whole clock rotates not just the hands.

You do not have to do all the view drawing in the same coordinate system. Also repeatedly transforming the paths you are drawing does not seem like the best approach. Better to save and restore graphics state to draw the bits in different coordinate systems, so your graphics model objects can be static. Your -drawRect would look conceptually like this:


  [[NSGraphicsContext currentContext] saveGraphicsState];

  [offsetTransform concat];

  (draw the clock face)

  [[NSGraphicsContext currentContext] saveGraphicsState];

  [rotateTransform concat];

  (draw the hands)

  [[NSGraphicsContext currentContext] restoreGraphicsState];

  (other drawing in the clock face coordinate system)

  [[NSGraphicsContext currentContext] restoreGraphicsState];

  (other drawing in the view bounds coordinate system)

Also this is much simpler when you update on your timer fire, all you have to do is make a new rotateTransform with the correct amount of rotation to put the hands at the current time.

By the way, remember that NSTimer fires are never early but can be arbitrarily late, so your 1-second tick may be sometimes 1.01 or 1.02 seconds, hence with the example code you posted the clock will probably run slow.

Hope this helps!

Bob S.

_______________________________________________

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


  • Follow-Ups:
    • Re: rotating an object around the center of a view
      • From: Ken Tozier <email@hidden>
References: 
 >Re: rotating an object around the center of a view (From: Erik Buck <email@hidden>)
 >Re: rotating an object around the center of a view (From: Ken Tozier <email@hidden>)

  • Prev by Date: NSURLConnection leaking on multi-threaded apps?
  • 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