It seemed to me that I remembered transferring some kind of Apple documentation when I learned how to use Core Animation, which showed how to customize animations that cannot be processed using the proper description that come with certain animations. Along the way, I came across some sample code from Apple, which is described as:
One gradient layer is displayed and constantly animated using new random colors.
This may be the answer to a specific task that you have already dealt with differently. I found it in the Documentation and API Reference document in Xcode, and the name of the sample code is just Gradients . (Please note that there is an original version 1.0 and an updated version 1.1, which was redone this year in April and therefore should be easier to use with current tools.
But the more important issue of creating custom animations that cannot be automated by Core Animation itself is to follow the Apple Cocoa Animation Programming Guide example in Using the NSAnimation Object . It is described in the NSAnimation Subclassification section , and the recommended method is shown in the Smooth Animations heading. You override the setCurrentProgress: method so that every time it is called, you first call Super , so that NSAnimation updates the progress value, i.e. your custom animated property, and then do any update or drawing needed for the next frame of your animation. The following are notes and sample code provided by Apple in the specified documentation:
As mentioned in the section “Configuring and processing progress indicators”, you can attach a series of progress indicators to the NSAnimation object and provide the delegate with an animation: didReachProgressMark: method for redrawing the object with each progress sign. However, this is not the best way to animate an object. If you have not set a large number of progress marks (30 per second or more), the animation will probably seem jerky.
The best approach is to subclass NSAnimation and override the setCurrentProgress method: as shown in Listing 4. The NSAnimation object calls this method after each frame to change the progress value. By intercepting this message, you can perform any redrawing or updating necessary for this frame. If you override this method, be sure to call the super implementation so that it can update the current progress.
Listing 4 Overriding the setCurrentProgress: method - (void)setCurrentProgress:(NSAnimationProgress)progress {
So basically you define a “progress value” (possibly consisting of several values) that determines the state of your custom animation and writes code that sets the current “progress value”, draws or changes what is drawn when the animation is on this is a specific condition. You can then start the NSAnimation animation using the usual animation tweaking methods, and it will execute your code to draw each frame of the animation at the appropriate time.
I hope that answers what you wanted to know. I doubt that I could find it easily by searching without having seen it before, since I finally had to go where I thought it was possible and go page by page on the whole topic to find it again!