Re: resizing window containing NSView with CALayer
Re: resizing window containing NSView with CALayer
- Subject: Re: resizing window containing NSView with CALayer
- From: julius <email@hidden>
- Date: Mon, 08 Aug 2011 10:14:17 +0100
On 8 Aug 2011, at 01:46, Graham Cox wrote:
>
> On 08/08/2011, at 5:52 AM, julius wrote:
>
>> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
>
>
> I didn't notice first time through that this is where your code resides (sometimes the most obvious errors pass by when you're looking out for a more subtle error). It's certainly wrong to put it there. A view will typically initialise its layer as part of its own initialisation, i.e. the layer set up should be done in the view's -initWithFrame: method.
I've done as you suggested.
Putting it in initWithRect resulted in no drawing showing up in the window.
I then put it in awakeFromNib and it drew ok but the problem remained as before.
I also did a variant of that by putting the root layer initialisation in the initWithRect and the assignment of colour to the layer background in awakeFromNib but that did not display anything either. (I only started looking at layers this Friday last so am a bit at sea with this technology).
So the program currently looks as follows.
There's nothing in the app delegate except a IBOutlet to the view.
and the view looks like this
// MyView.m
#import "MyView.h"
@implementation MyView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
-(void)awakeFromNib {
CALayer * zCALayerRoot = [CALayer layer];
zCALayerRoot.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
zCALayerRoot.needsDisplayOnBoundsChange = YES;
[self setLayer: zCALayerRoot];
[self setWantsLayer:YES];
self.layer.backgroundColor = CGColorCreateGenericRGB(0.0,0.0,1.0,1.0);
} // end awakeFromNib
- (void)drawRect:(NSRect)dirtyRect {
} // end drawRect
@end
>
>> I get exactly the same behaviour if I leave out all the layer stuff and instead code the following in the view
>>
>> - (void)drawRect:(NSRect)dirtyRect {
>> [[NSColor blackColor]set];
>> [NSBezierPath fillRect:[self bounds]];
>> } // end drawRect
>
> Well, in that case the struts (which end up setting the autoresizing mask for the view) must either be set incorrectly,
I went back into IB to check this. As far as I can tell everything is set correctly.
I have put a copy of the project up here
http://juliuspaintings.co.uk/cocoa/LayersInView3.zip
I have also put a copy of the project which contains only the view - no layers here
http://juliuspaintings.co.uk/cocoa/LayersInView2.zip
> or else the view in IB that you think you're setting is not the view object you actually end up with in your window. A common mistake is to add the view in IB and also create and add it in code. Do one or the other, never both.
Only created it in IB
Julius
http://juliuspaintings.co.uk
_______________________________________________
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