Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 03-14-2010, 09:37 AM   #1 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default How to tell if a layer has active animations?

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
Duncan C is offline   Reply With Quote
Old 03-14-2010, 12:55 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default I found a solution for my app, but...

Quote:
Originally Posted by Duncan C View Post
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
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 272
20 members and 252 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:01 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0