Search code examples
iphoneioscalayer

Analog clock using CALayers


I'm trying to make an analog clock for the iPhone, in which the clock hands will automatically update to the current time. I also want the clock hands to be images, unlike this: http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html. What would be the easiest way to create this using CALayers to rotate the images/hands?


Solution

  • There are two properties of CALayers that may be of interest to you - the anchorPoint and the transform. Set the anchor point at the origin around which you want to rotate the images, calculate the angle of rotation, make a transformation matrix from it (using CATransform3DMakeRotation around the appropriate axis) and set the transform on the layer.

    It's all explained in detail here.