Re: should I use CALayer .. ?
Re: should I use CALayer .. ?
- Subject: Re: should I use CALayer .. ?
- From: Scott Anguish <email@hidden>
- Date: Sun, 31 Jan 2010 14:56:11 -0500
On Jan 29, 2010, at 6:05 AM, Roland King wrote:
I'm failing to understand I think exactly what CALayer gives me and
thus whether or not it's good for something I'm working on. I've
read the documentation pretty thoroughly I think but I'm not getting
it.
Target here is IPhone OS, which may matter. Concept is a view with a
number of 'objects' drawn on it, 5, 15, 15, 20 .. that's about it.
They can move around, they can have some kind of z-ordering amongst
themselves. The objects need to draw themselves instead of having
one big drawRect: statement.
The CA objects have three methods that they can draw. And, with the
exception of assigning an image to the contents property, all are
analogous with drawRect:.
One way to do it would be to have one UIView which asks each object
"are you in this rectangle" and if so "please draw nicely" at the
correct place on the UIView's layer. I was a bit bothered however
what would happen if I move an object from one point to another, at
the least I'd have to invalidate the entire rectangle from the
corner the thing started, to where it ended up to make sure
everything it passed over gets redrawn and perhaps even that's not
enough.
UIView’s are largely layers. Animating them from point A to point B
requires no extra effort, with respect to invalidation, than Core
Animation.
So I read about CALayers and was trying to understand whether I get
something for free over and above the method just described. Do
CALayers retain their content so that as they are moved they don't
redraw themselves but are just recomposited in a different area of
the screen? That would of course be a win as the first method means
redrawing the object in different locations on the UIView's layer,
recomposition means I drew it once and that's it. How about other
layers, if the content is retained, then I wouldn't have to redraw
those either, the entire movement just becomes a compositing
exercise by the GPU.
Consider that Core Animation does NOT handle events, does NOT handle
touches, does NOT handle any sort of touch tracking...
If CALayers don't retain content (or perhaps only a limited number
of them can if there's a GPU limitation) then there would still be
redrawing calls but, it seems, I wouldn't have to worry about
figuring out what layers need redraws (ie figuring out the big dirty
rectangle), something else would be working that out and just
telling the affected CALayers to redraw.
You never have to figure out the ‘big dirty rectangle’. Not in UIView,
not in NSView, not in Core Animation.
Am I understanding CALayer at all or am I totally out in the woods
here and have misunderstood the concepts?
It isn’t CA you’re not understanding, it’s UIView.
_______________________________________________
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