views:

286

answers:

1

I'd like to create a dial with similar behavior to some of the retro phone apps. These have a circular dialer that lets you spin it around with your finger. Any ideas how that is created or some links that discuss aspects of it?

+2  A: 

Create your circular dial with numbers on it. Create your moving dial part as a transparent image centered over the number dial so you can see the numbers through the transparent holes. Apply a small image for the finger stop over both. When you get a touch in one of the hole regions track the motion of the finger. As the finger moves rotate the transparent dial image to follow it using a transform matrix. If the finger moves the wrong way or when the finger is lifted or moves outside the rotating dial the dial is "released" and you undo the rotation using a suitable speed to simulate a spring loaded return.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:d];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationBeginsFromCurrentState:YES];
CGAffineTransform transform = CGAffineTransformMakeRotation(/* some angle */);
image.transform = transform;
[UIView commitAnimations];

Detecting the actual number dialed could be done a number of ways, from creating invisible buttons on the dial and grabbing events from those or by calculating the angle of rotation required to return the rotating dial to home. I don't think implementing it would be very difficult, it's the artwork that would be hard.

Adam Eberbach
Thanks a ton! How do you make it keep up with the user's speed rather than some set speed via setAnimationDuration:?
4thSpace
You can get the touch coordinates fairly easily. If you think about a mechanical phone dial you can rotate it at pretty much whatever speed you like if you push hard enough. So while touches are changing, periodically (timer? every nth touch notification?) work out the angle between the previously sampled point, the new point and the centre pivot point and do a fairly quick rotation (as above) to follow the finger. I'd like to be able to move it in the clockwise direction at almost any speed but for it to always return in the anticlockwise direction at the mechanical spring speed.
Adam Eberbach