small medium large xlarge

Logo_pragsmall
14 May 2009, 23:09
Douglass Turner (10 posts)

Hi,

I’m starting to play with layers and this rather innocent looking code generates a bunch of frustrating warnings at compile time:

1) [view setLayer:[CALayer layer]]; creates the following warning: warning UIView may not respond to -setLayer. Checking the header file I was unable to even find the method (!?)

2) view.layer.backgroundColor = [UIColor redColor]; creates the warning due to the fact that the layer getter is readonly

3) [view setWantsLayer:YES] generates a warning like 1) above.

What am I doing wrong here. the method calls are straight out of the Prag Prog Core Animation book.

Thanks, Doug

`

- (void)loadView {
	

    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	[view setLayer:[CALayer layer]];

	view.layer.backgroundColor = [UIColor redColor];

        [view setWantsLayer:YES];
	
	// Do stuff ...

    self.view = view;
    [view release];
}

`
Biopic_100x100_pragsmall
15 May 2009, 13:24
Bill Dudney (917 posts)

Hi Doug,

On the phone view’s are automatically layer backed. If you want to change the class of the layer a view uses override the class method on UIView in your subclass with something like this.

+ (Class)layerClass {
  return [MyLayer class];
}

if you just want to use the layer then do someting like this;

[myview.layer addSublayer:myotherLayer];

good luck!

You must be logged in to comment