views:

1498

answers:

2

What is the difference between a Layer Backed View and a Layer Hosting View in Core Animation?

What are the steps to setting up each and when is it appropriate to use either type?

+3  A: 

A layer backed view contains Cocoa or Cocoa Touch UI controls and can be animated using the animator proxy. Layer backed views allow you to animate your UI and help to reduce the overhead of drawing by caching the views contents on a core animation layer. Create a Layer backed view by setting the wants layer property:

NSView *layerBacked = [NSView new];
[layerBacked setWantsLayer:YES];

A layer hosting view provides a layer for direct manipulation hosted by an NSView or UIView. Layer hosting views can be used for embedding core animation drawing and animation anywhere you can put an NSView:

NSView *layerHosting = [NSView new];
[layerHosting setLayer:[[CALayer new] autorelease]];
alfwatt
Also note that in Cocoa Touch all UIView's are layer backed by default
Jason Harwig
A: 

Do you not need to do... [layerBacked setWantsLayer:YES]; ..when you are creating the layer hosting view? you can just set a layer without doing that part?

Once you've called [view setWantsLayer:YES] it will be a layer backed view, if you want to use standard controls that's the way to go.If you want to use the view to host a CALayer for custom drawing make sure that [layer setWantsLayer:NO]
alfwatt