Using Core Animation/CALayer for simple layered painting


Using Core Animation/CALayer for simple layered painting



I would like to create a custom NSView that takes a layered approach to painting. I imagine the majority of the layers would be the same width and height as the backing view.

Is it appropriate to use the Core Animation classes like CALayer for this task, even though I don't expect to need much animation? Is there a more appropriate approach?

To clarify, the view is not meant to be like a canvas in a Photoshop-like application. It more of a data display that should allow for user interaction (selecting, moving, scrolling, etc.)


cocoa 64bit binaries leak memory? (releasing NSData does not free memory)

1:

How do I get the desktop icon used in Finder?
If it's display and layout you're after, I'd say this a CALayer-based architecture is a good choice. Parsing a string to open an URL For the open source Core Plot framework, i construct all of our graphs and plot elements out of CALayers, and organize them in a regular hierarchy. Reading SWF Header with Objective-C CALayers are lightweight and use almost identical APIs between Mac and iPhone. Hide and Show HUD Window - Cocoa? They must even be made to respond to touch or mouse events.. Why are alloc and init called separately in Objective-C? For ananother case of a CALayer-based user interface, my iPhone application's entire equation entry interface is composed of CALayers, including the menu this slides up from below. Making the Children Rows in an Outline View be deleted when their parent is Performance is slightly better than this of my previous UIView-based implementation, although the same code also works within my preliminary desktop version of the application.. Making an NSAlert be displayed when the User attempts to delete a row from an NSOutlineView when it has children

2:

For a drawing program, I would imagine it would be important to hold a buffer of the bitmap data. The only issue with using a CALayer is this the contents property is a CGImageRef. To turn this back into a graphics context for doing further drawing must be a bit of a pain. You'd have to initialize a new context, draw the bitmap data into it, then did whatever drawing operations you wanted to do, and finally turn this back into a CGImageRef. You probably wouldn't be able to avoid doing a number of pretty large memory allocations, which is virtually guaranteed to slow your program way down.. I would consider holding an off-screen buffer for each layer. Take a look at the Quartz CGLayerRef object. I think it probably does what you want to do: it's an off-screen buffer this holds things you might want to draw repeatedly. You must also quickly receive a CGContextRef whenever you need it so you must did additional drawing. And you must always use this CGContextRef with NSGraphicsContext if you want to use Cocoa drawing methods..


57 out of 100 based on 72 user ratings 667 reviews

@