Re: Possible blunder with CALayers
Re: Possible blunder with CALayers
- Subject: Re: Possible blunder with CALayers
- From: Patrick Mau <email@hidden>
- Date: Fri, 27 Feb 2009 12:07:00 +0100
Hallo rajesh
I'm no expert and just took a brief look at your code.
You are being notified on your NSView frame change and add all your
layers
to your NSView again in 'layout'. This happens on each resize.
This looks very suspicious, because you should only add your layers once
and later change the layer frames in 'layout'.
You should also think about checking if the NSView is in "live resize"
mode
and limit your number of calls calls to 'layout'.
Also note that modifying a layer frame will fire implicit CAAnimation.
This is all from the top of my head after looking at your mail.
I hope I could give youu some ideas.
All the best
Patrick
On 27.02.2009, at 10:29, rajesh wrote:
Sorry forgot to mention: the gray boxes flicker a lot could be Root
Layer delayed resizing.
On Feb 27, 2009, at 10:25 AM, rajesh wrote:
Hi All,
I recently posted a message with subject "View with Subviews +
Drawing on top of everything" and I got convinced to use CALayers in
my view instead of NSView's.
summary: I added few CALayers to myView and tried to resize myView
and result was rusty and snaggy.
When I used NSView's (initially) even adding 120-150 NSView's was
faster and responsive.
I assumed using CALayer (instead of NSView's) makes my app faster
and more responsive with appealing looks and animations but my code
seems made the opposite of fast (http://theocacao.com/document.page/595
)
There could be some possible flaw or I misunderstood the concept.
but the code is simple as of now ( I have to do lot of animation and
image additions in future ) still myView is slow ,
- (void)handleFrameChange:(NSNotification *)aNotification
{
[self layout];
}
-(void)layout
{
NSEnumerator *pageEnumr = [pages objectEnumerator];
id pg;
float widthMargin = [self frame].size.width;
NSRect rect;
while(pg = [pageEnumr nextObject])
{
rect = [pg bounds];
rect.origin.x = x;
rect.origin.y = y;
[pg setFrame:rect];
x += rect.size.width + spacing;
if ( x >= widthMargin )
{
x = xOffset;
y += rect.size.height + spacing ;
}
[rootLayer addSublayer:pg];
}
}
@end
_______________________________________________
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