Re: CALayer resizing puzzle
Re: CALayer resizing puzzle
- Subject: Re: CALayer resizing puzzle
- From: vincent habchi <email@hidden>
- Date: Fri, 22 Jan 2010 08:53:02 +0100
Hi Scott,
> this specific example of course assumes that you’re using the iphone. But, the technique should be sound for what you’re trying to do.
>
> The technique is applicable to use a pool of multiple views to contain smaller amounts of the content. the advantage is that you can render or fetch the content that is visible (or could be next) only when required. As you show new content relocate the views, create the layers (which you could do in the reusable pool) and the set the content. Then move the no longer visible layers back to the pool, clearing the content to save space.
Ok, this is an already common scheme to render bitmap images: you prefetch surrounding areas in background and so you can scroll to them quite fluidly when needed, discarding useless tiles and creating new ones on the fly. I'll try to do that to render vector data, even if it's a lot of work. I'll have to dig into threads and all that stuff.
Yet, at the same time, I'm baffled by the fact that I have not found how to resize a CALayer the way an NSView resizes. If what I found out is right, when you resize a layer, the scale is automatically adjusted. Does that mean that the content property is altered not only when you set it explicitly, but also when you draw on the layer via [DrawLayer: inContext:]?
To answer to Douglas, the code is very simple. Imagine a NSView with a backing layer and a sublayer. When the user clicks and drag the mouse, I simply update the position property of the sublayer by the amount of pixels the mouse moved since last event. This way, the drawing moves along with the mouse, but the origin also. To be more specific, here it is:
// Move coordinates of layer
int dx = dragMousePosition.x - intermediateMousePosition.x;
int dy = dragMousePosition.y - intermediateMousePosition.y;
CGPoint pt = [backgroundLayer position];
pt.x += dx;
pt.y += dy;
[backgroundLayer setPosition:pt];
intermediateMousePosition = dragMousePosition;
The CGPoint variable intermediateMousePosition gets initialized at the MouseDown event, and dragMousePosition is the current position of the mouse.
Thanks a lot for your help,
Vincent_______________________________________________
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