On Sat, Mar 12, 2011 at 10:03 AM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote: > Dear list, > > I have a layer backed view whose layer contains many sublayers. The problem > is that the layer doesn't get drawn in the view when the app starts. If I > resize the window, then the layer and all its sublayers draw properly. I've > solved this problem before with what seemed like a magic collection of > [calayer setNeedsDisplay] and [view setNeedsDisplay:YES], but this time I > can't seem to get it to work. Therefore, I thought I'd ask if anyone knows > the correct way to do this. > > My view subclass makes its layers like this: > > - (void) setupLayers > { > NSLog(@"Setting up layers"); > CALayer *rootLayer = [CALayer layer]; > rootLayer.layoutManager = [CAConstraintLayoutManager layoutManager]; > [self setLayer:rootLayer]; > [self setWantsLayer:YES];
You don't have a layer-backed view. You have a layer-hosting view. This means -setNeedsDisplay: is irrelevant, because -drawRect: doesn't do anything. > yearLayer = [[CAYearLayer alloc] initWithDate:self.year > dataSource:self.datasource]; > [rootLayer addSublayer:yearLayer]; > [rootLayer setNeedsDisplay]; > [self setNeedsDisplay:YES]; > } > > and the setupLayers is called in awakeFromNib of the view subclass. Are you sure that "wants layer" is turned OFF in the nib? IIRC, if that's turned on, the nib loading machinery will do a delay-perform that will change your view's layer *after* -awakeFromNib is called. Since you have a layer-hosting view, you do not want that checkbox checked. Rather than calling -setLayer:, you should probably be overriding -makeBackingLayer instead. We do that, and then call [self setWantsLayer:YES] from -viewDidMoveToSuperview. We also call [[self enclosingScrollView] setWantsLayer:YES], which is required if your view is contained in a scroll view. --Kyle Sluder _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com