Re: coreAnimation CALayers and NSViews, which to use ?
Re: coreAnimation CALayers and NSViews, which to use ?
- Subject: Re: coreAnimation CALayers and NSViews, which to use ?
- From: David Duncan <email@hidden>
- Date: Wed, 13 Jan 2010 09:10:43 -0800
On Jan 13, 2010, at 7:43 AM, Nicolas Berloquin wrote:
> Hi !
>
> I'm new to coreAnimation, and there is something that I don't grasp yet. I'd like to composite a series of images (sometimes a few hundred) inside a view.
> Those images will sometimes remain where they are, or be resized or moved around.
>>
> From what I understand, backing an NSView with a CALayer brings an optimized rendering pipeline (I guess using the GPU etc).
> From the docs, CALayers are described as model objects, used to orchestrate the drawings and animations. Alright.
> But the docs also describe how to use CALayer delegates to handle the actual drawing (drawLayer: inContext:).
> So this is getting me a bit confused.
You can get content into a CALayer either by drawing content from Quartz (which is what the -drawLayer:inContext: delegate method is for) or by setting the contents property of the layer to one of a view supported class types (CGImageRef, NSImage on 10.6+, or the contents of another layer).
When you layer back an NSView, it implements the machinery to get whatever drawing occurs inside of -drawRect: into the contents of the layer.
> I've started to create a simple view hierarchy with a scrollview and an NSView in it, in IB, and I checked the wants coreAnimation layer on my NSView.
> Should I then override drawRect: in my view and draw each of my images there (intersecting the visible rect),
> or rather should I not create an NSView, and add programmatically a CALayer to the scrollview and override drawLayer: inContext: and do the drawing there ?
> Or (but this sound much heavier) should I add many NSViews or NSImageViews to the backing layer and move/resize them afterwards ?
The simplest way to get started is to pretend like layers don't exist and just build your view hierarchy as normal. Then as you already have, just turn on the Core Animation layer for root view (which will automatically turn on core animation for all child views). Once you've gotten the hang of what AppKit has to offer (and it does have quite a bit to offer) then you can consider diving deeper into using Core Animation directly.
--
David Duncan
Apple DTS Animation and Printing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden