在我的應用程序中,我使用IKImageBrowserView與背景。如果wantLayer沒有 - 所有罰款和IKImageBrowserView看起來不錯。但是,如果我啓用了wantsLayer(在父視圖中)IKImageBrowserView中的背景已損壞。 (對不起英文不是我的母語,我找不到正確的詞)。IKImageBrowserView與背景和wantsLayer
如果我理解正確,在這個片段的問題。但我看不到在哪裏。
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);
感謝
有趣但它現在幫助我的情況.. – user3229853