在我的应用程序中,我使用带有背景的 IKImageBrowserView。如果想要Layer NO - 一切都很好,IKImageBrowserView 看起来不错。但是,如果我启用了 WantLayer(在父视图中),则 IKImageBrowserView 中的背景已损坏。(抱歉英语不是我的母语,我找不到正确的单词)。
如果我理解正确,这个片段中的问题。但我看不到在哪里。
NSRect visibleRect = [owner visibleRect];
NSRect bounds = [owner bounds];
CGImageRef image = NULL;
NSString *path = [[NSBundle mainBundle] pathForResource:[@"metal_background.tif" stringByDeletingPathExtension] ofType:[@"metal_background.tif" pathExtension]];
if (!path) {
return;
}
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:path], NULL);
if (!imageSource) {
return;
}
image = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
if (!image) {
CFRelease(imageSource);
return;
}
float width = (float) CGImageGetWidth(image);
float height = (float) CGImageGetHeight(image);
//compute coordinates to fill the view
float left, top, right, bottom;
top = bounds.size.height - NSMaxY(visibleRect);
top = fmod(top, height);
top = height - top;
right = NSMaxX(visibleRect);
bottom = -height;
// tile the image and take in account the offset to 'emulate' a scrolling background
for (top = visibleRect.size.height-top; top>bottom; top -= height){
for(left=0; left<right; left+=width){
CGContextDrawImage(context, CGRectMake(left, top, width, height), image);
}
}
CFRelease(imageSource);
CFRelease(image);
谢谢