I have an Image that I want to dangle back and forth (once) around a fixed point. So I have the following code:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
myDial.transform = CGAffineTransformMakeRotation(degreesToRadians(45)); //lineA
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
myDial.transform = CGAffineTransformMakeRotation(degreesToRadians(0 )); //lineB
[UIView commitAnimations];
What happens when I run the above code is that lineA gets executed immediately (and not in 1.5 seconds). Right after that lineB gets executed in 1.5seconds. I want both animations to take 1.5 seconds each. How can I do this
Instead of trying to have two UIView animations together to create one visual animation, you could just use Core Animation and do it all in one animation. Using Core Animation you can tell the animation to automatically reverse (go to 45 degrees during 1.5 seconds and then back again during the same duration) and you won’t have to care about timing the two animations together. You could do it like this:
If you haven’t imported QuartzCore.framework into your project and imported the , you’ll need to do so for Core Animation to work.