开发者

Want to have a CALayer to display inside the window

I'm trying to get a CALayer with a black background to display. I've attached the AppDelegate as the delegate to the file's owner. The console reports correctly the "awaking from nib..." log statement. I however, just see a blank grey window (335x390 in size), with no black box drawn in the middle. What concept am I missing?

Thanks in advance for the help,

Charles

#import "AppDelegate.h"
#import <QuartzCore/QuartzCore.h>
@implementation AppDelegate

-(void)awakeFromNib;
{
  NSLog(@"awaking from nib...");
  [[window contentView] setWantsLayer:YES];

  layer = [CALayer layer];
  [layer setBounds:CGRectMake(0.0,0.0,100.0,100.0)];

   // center the animation layer
   [layer setPosition:CGPointMake([[window contentView] frame].size.width/2, [开发者_C百科[window contentView]frame].size.height/2)];
   CGColorRef color = CGColorCreateGenericRGB(0., 0., 0., 1);
   [layer setBackgroundColor:color];
   CFRelease(color);

   [layer setBorderWidth:5.0f];

   [[[window contentView] layer] addSublayer:layer];      
}
@end


The construction code for your custom layer looks correct, although a color with an RGBA of (1,1,1,1) will be white, not black.

I'd verify that your outlet to your window property is connected correctly (make sure it's non-nil), and that the contentView is non-nil. If those are looking good, you could try to provide your own custom layer for the contentView by doing something similar to the following:

[[window contentView] setLayer:[CALayer layer]];
[[window contentView] setWantsLayer:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜