I've been advised to try CADisplayLink
to rotate a UIIMageView
. I'm building this app using Storyboard.
I need to start and stop the animation, when the screen is tapped. I also need to track the angle at which the rotation stopped when the screen was tapped.
I've found this tutorial HERE but it's not exactly helpful to me.
I've also found a couple of small examples (here's one), but I couldn't get it to actually animate. From what I took from the above example, my image rotated the once, then just stopped.
Other that that, i really can't find a good tutorial or example of how to use CADisplayLink
to rotate my UIImageView
continuously, until tapped, then continue to rotate when tapped again and finally storing the angle of rotation.
To give you an idea of what I'm trying to achieve, it's basically a clock face, and as a clock hand rotates, you can start and stop it by tapping, and retrieve the angle.
Does anyone know a good example? or maybe could help me out here. Thanks.
UPDATE / EDIT
Using Rob's awesome Obj-C answer below in my app works perfectly. Incase anyone is interested, this is how I track the angle of rotation and display it to the screen:
Every time the HandleDisplayLink
is called, I called this method: [self calculateDisplayAngle];
The method is simple:
- (void)calculateDisplayAngle{
currentRotationAngle = self.percent*360; //360 because I changed kDuration = 1;
self.AngleLabel.text = [NSString stringWithFormat:@"Angle: %.2f",currentRotationAngle];
}