Re: Problems understanding CALayer geometry
Re: Problems understanding CALayer geometry
- Subject: Re: Problems understanding CALayer geometry
- From: Matt Neuburg <email@hidden>
- Date: Sat, 21 Nov 2009 14:58:02 -0800
- Thread-topic: Problems understanding CALayer geometry
On Sat, 21 Nov 2009 17:21:55 +0200, Henri H?kkinen <email@hidden>
said:
>Hello.
>
>I am deriving my own custom CALayer class for my custom NSView class but there
is something I don't quite understand about the geometry.
>
>This is how I create the layer in awakeFromNib: of my custom NSView class:
>
>- (void)awakeFromNib {
> MyLayer *myLayer = [MyLayer layer];
>
> self.layer = myLayer;
> self.wantsLayer = YES;
>
> myLayer.needsDisplayOnBoundsChange = YES;
> myLayer.position = CGPointMake(100.0, 100.0);
> myLayer.bounds = CGRectMake(0.0, 0.0, 100.0, 100.0);
>}
>
>And this is how I draw the layer in MyLayer:
>
>- (void)drawInContext:(CGContextRef)context {
> CGContextFillRect(context, [self bounds]);
>}
>
>I don't any other methods overidden by neither of the classes.
>
>However the layer somehow automatically gets resized to fill the whole view
(that is, the view is rendered completely in black by the CGContextFillRect
call). How I understand this, I think it should just draw a 100x100 rectangle at
the position (100, 100). What am I missing?
A layer is not something different from a view, so much as it's an
encapsulation of the drawing done for that view.
So if you want to cover a view with a *smaller* layer, it needs to be a
sublayer of the view's layer. (Or, it could be the layer of a smaller
subview of the view.)
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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