1

我想将棋盘背景添加到 IKImageView 以查看透明图像。我正在尝试将带有棋盘图像的 CALayer 设置为带有消息setOverlay:forType 的 IKImageView

CFURLRef imageURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),(CFStringRef)@"bgImage.png", NULL, NULL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageURL,NULL);
CFRelease(imageURL);
CGImageRef image = CGImageSourceCreateImageAtIndex(imageSource, 0,NULL);
CFRelease(imageSource);
CALayer *bgLayer = [[CALayer alloc] init ];
[bgLayer setContents:image ];
[ imageView setOverlay:bgLayer forType:IKOverlayTypeBackground ];

但不起作用。我在控制台中收到此消息

could not add '<CALayer: 0x101d039a0>' linkedTo 'kIKRootLayerType'

有谁知道出了什么问题或任何解决方法?

谢谢

4

1 回答 1

2

The error message is because the view is not attached to top view.

Finally I added the checkerboard background to the NSScrollview container of the IKImageview, this way the background layer auto resizes

CALayer *layer=[[SquareBackgroundLayer alloc] init];
[[ scrollView contentView] setLayer:layer];
[ layer release ];

I hope this is helpful for anyone.

于 2011-06-28T17:39:29.867 回答