Re: More CALayer Questions
Re: More CALayer Questions
- Subject: Re: More CALayer Questions
- From: Scott Anguish <email@hidden>
- Date: Tue, 8 Jul 2008 05:54:21 -0400
It's hard to tell, but if you're using a view that you expect to both
draw its own content, and that you expect to manipulate and interact
directly with the layer (i.e. adding sublayers) you'll have issues.
From the hybrid app docs in Animation Overview
You can use a combination of layer-backed views, non-layer-backed
views, and layer-hosting views in a single user interface with two
caveats:
• All the subviews of layer-backed views are automatically layer
backed. To improve performance, you should avoid making views
descendants of layer-backed views if they don’t require animation or
cached drawing.
• You must host your custom Core Animation layers in a single layer-
hosting view rather than inserting them into a layer hierarchy managed
by a layer-backed view.
If you're doing the second case, none of that view information aside
from the frame is at all relevant. The view simply acts as a container.
The 'root' layer (that is the layer that is hosted by the view) will
always resize so that it fills the entire view. But because frame and
bounds in layers behave differently than views (the relationship is
much simpler than the scaling that happens in views) the content of
the layer won't scale as a result of the frame changing.
You shouldn't modify the bounds of a view that is layer-hosting... in
fact, it's easiest to simply remember that the root layer resizes to
fit the view size, and aside from that how the coordinate system
relates is immaterial.
If you're adding sublayers to that layer, then you can use springs and
struts to resize those layers (to actually scale the displayed content
of a layer you'll need to either set the contentsGravity as
appropriate (see "Positioning Content Within a Layer"), or if you're
providing the content via the a delegate or subclassing and
implementing one of the drawing routines, set the
needsDisplayOnBoundsChange method to YES so you can redraw the content
when the bound changes..
An update to the view chapter that includes the layer-backing
information is forthcoming. But to be honest, it wouldn't have covered
most of the questions you're having with coordinate system
relationships because if you're layer-backed, you should be ignoring
the layer completely. If you're layer hosting, you should only
consider the layer itself as being important (aside from the fact that
it automatically resizes to fit the view).
On Jul 7, 2008, at 3:42 PM, Gordon Apple wrote:
What I'm trying to do is conceptually very simple, I just want to
scale
the view and have its layer position and scale the same, so that
drawing
into the scaled view comes out the same whether layer-backed or
not. Then,
once that works, I will try stacking individual sub-layers again.
_______________________________________________
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