• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CALayer resizing puzzle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CALayer resizing puzzle


  • Subject: Re: CALayer resizing puzzle
  • From: douglas welton <email@hidden>
  • Date: Fri, 22 Jan 2010 07:54:16 -0500

Vincent,

Have you checked the values of dx and dy in the debugger?  Shouldn't those variables be declared as CGFloats as opposed to int?

In regards to resizing the layer when the enclosing view resizes, what values have you set for the layer's autorezingMask property?

regards,

douglas

On Jan 22, 2010, at 2:53 AM, vincent habchi wrote:

> 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

  • Follow-Ups:
    • Re: CALayer resizing puzzle
      • From: vincent habchi <email@hidden>
References: 
 >CALayer resizing puzzle (From: vincent habchi <email@hidden>)
 >Re: CALayer resizing puzzle (From: Scott Anguish <email@hidden>)
 >Re: CALayer resizing puzzle (From: Scott Anguish <email@hidden>)
 >Re: CALayer resizing puzzle (From: vincent habchi <email@hidden>)

  • Prev by Date: Re: NSRulerView and inches
  • Next by Date: Performance of NSArrayController update with Display Pattern bindings
  • Previous by thread: Re: CALayer resizing puzzle
  • Next by thread: Re: CALayer resizing puzzle
  • Index(es):
    • Date
    • Thread