views:

59

answers:

1

Consider a circle. Now consider a radius of the circle, drawn from the center of the circle towards the right. Now imagine that the radius is rotating about the center of the circle, sweeping out an area as it rotates. My problem is: I want to use iPhone's animation techniques to fill up the swept out area with a different color from the background area of the circle, as the radius rotates from 0 degrees to any chosen number of degrees about the circle.

I've looked through the Core Animation API, KeyFrame Animations, etc. but I am not able to find out how to do this. Any hints will be most welcome.

Thanks, Sandeep

+1  A: 

Check out CAShapeLayer. It lets you animate between two Core Graphics paths, which can be as complex as you want. In this case, you might want to animate between a path which defines a thin filled wedge and a filled wedge that covers a larger angle of the circle. You may need to use a CAKeyframeAnimation to make sure that it is animated in the sweeping motion you desire, and in the direction you want.

Brad Larson
Hi Brad, I am very grateful to you for your help. I've been stuck on this problem for quite some time. I have been looking through the documentation on the CAShapeLayer, and it looks like this will solve my problem.Thanks again.
Sandeep
I checked out the CAShapeLayer class. It turns out that the CABasicAnimation class has a "fromValue" and a "toValue" property, which can be set to the starting path and the ending path, and the CABasicAnimation can then be added to the CAShapeLayer to get an animation that goes from the starting path to the ending path. But I need to use a CAKeyframeAnimation - which does not offer "fromValue" and "toValue" properties for the "from" (starting) path and the "to" (ending) path. My question is: how do I use the CAShapeLayer class with the CAKeyframeAnimation class?
Sandeep
@Sandeep - CAKeyframeAnimation takes an array of key values to hit at specific points during the animation. In this case, those values would be CGPathRef paths, cast as id (example: (id)path, (id)path2, ...).
Brad Larson