2008 04 24Core Animation Bindings
In Core Animation,
CALayers are live : they're created and stay here until they're destroyed, just like DOM nodes in an html page. This is in contrast to Cocoa drawing, or the canvas html tag, where drawing is done programmatically when needed. So when using CALayers to display data, we need to match source objects and CALayers.
Just a hash
We use a custom view CAListView and observe data in an NSArrayController. To update the view, we need to know when to create / delete layers and when to update them to reflect their source object.
- creating/deleting layers observe changes by binding to
arrayController.arrangedObjects— this will tell us when objects are created, moved, and deleted. Use aNSMutableDictionaryto store theCALayers, using their source object's pointer as a key. To know when to createCALayers, loop through the objects array and query theNSMutableDictionaryfor an existingCALayer. If not found, create a new one. To know when to deleteCALayers, loop through theNSMutableDictionaryand check if its keys (pointers to objects) are still in the objects array. If not, delete them. - updating layers bind once more with bastard observing to observe all the keys of all the controller's objects. When an object changes, query the
NSMutableDictionaryfor knowing whichCALayerto update. (if it's aCATextLayer, update it withlayer.string = [observedObject name], if it's a color change, withlayer.backgroundColor = …, etc.)
Sample code
Core Animation
- CocoaNav a Cocoa Class Browser using Core Animation
- Core Animation Starfield Core Animation sample using 3D layers
CoreAnimationStarfield.zip
- Core Animation culling problems Don't setup a projection transform on the root layer !
- Threaded Core Animation while on the main thread, update your display with
[CATransaction commit]
CoreAnimationUpdateOnMainThread.zip
- Core Animation Bindings binding Cocoa objects to
CALayers
Core Animation Bindings.zip
- Core Animation Phantom Fade seeing ghosting ? Use two transaction to create and animate your objects
CoreAnimationPhantomFade.zip
- Photoshop-like compositing with Core Animation
Blending Modes.zip
