Quote:
Originally Posted by Duncan C
An app I am working on implements an animated compass rose that points towards north on a 3Gs, plus a heading arrow that rotates to keep pointing towards a selected point. As the user moves, both things rotate with animation to keep pointing where they should. The animation should be smooth, but sometimes it jerks around.
I suspect that what's happening is that sometimes a compass heading change comes in while the previous animation is still in progress. I think the thing to do in that case is to wait for the previous animation to finish before starting a new one.
Is there an easy way to tell if a layer has active animations running on it? I could create an "isAnimating" flag in my view controller for my layers, and have my animation delegate clear the flag when the animation completes, but it would be good to be able to query a layer for active animations rather than having to keep track of it.
Looking at the documentation for CALayer, I can ask for a list of keys to currently active animations using the -animationKeys method, and then ask for each animation by it's key using the -animationForKey method. However, if I have set my animations to removedOnCompletion = FALSE, I assume those animations will still be in place in the layer. The animations have delegate methods to notify me when they start and stop, but no way to query them for state.
Thanks in advance for any help you can offer.
Regards,
Duncan C
WareTo
|
Well, I found a solution for the app I am working on.
I made my view controller a delegate of the animation objects I add.
I added an instance variable animationCount to my view controller.
In my animationDidStart/animationDidStop animation delegate methods, I increment/decrement my animationCount.
When I want to update the compass setting, I check AnimationCount. If it is >0, I save the new compass heading, set a "animationWaiting" flag, and return.
Also in my animationDidStop method after I decrement animationCount, if animationCount == 0 and animationWaiting == TRUE, I re-invoke the method that creates an animation to update the compass orientation.
I would still like a way to tell if a layer has any animations running on it. What I did works for this use, but I can see other situations where it would be useful to query a layer for ACTIVE animations, but I can't see a way to do that.
Does anybody know a way to do that?
Regards,
Duncan C
WareTo