Claireware Software

Software for Your Mac and iPhone

Custom Animation with Sound

For a project I am currently working on, I need to have more control over an animation sequence of images then what the built in support that UIView or CALayer provides. The important features I needed that are not provided by the iPhone SDK classes include sound coordination with particular images and heterogeneous frame durations. Due to my personal style of app development, I also wanted the animation sequence to be configurable from a property list file. By supporting property list configuration, making changes to an animation sequence would be as easy as editing a property list file. I personally loath hard coding image and sound file names into my app's code, as experience tells me I will be changing them frequently.

When designing a class to accomplish my requirements, I quickly realized that it would be better if I drew animation into a CALayer rather than a UIView. My specific use case required the compositing of several images, some not part of the animation sequence, to form the final image. While you can accomplish this by nesting non-opaque UIView's, CALayer is much more lightweight than UIView, partly due to it not being required to deal with the UIResponder duties. Thus, drawing an animation directly into a CALayer and managing compositing by nesting CALayers would yield superior performance.

The CALayer-derived animation manager I built is embodied in the class MKSoundCoordinatedAnimationLayer. However, I realize that UIViews are very easy to work with, especially from Interface Builder. So I created the UIView-derived MKSoundCoordinatedAnimationView class that simply wraps the MKSoundCoordinatedAnimationLayer class. If you don't know how to make a UIView backed by a CALayer, this might be interesting code for you to look at.

The code is available on GitHub here.
blog comments powered by Disqus
Site logo
Claireware Software
© 2009-2012 Michael Kamprath • Privacy PolicyLegalContact