2011-02-24 4 views
2

NSSplitView에있는 NSScrollView 안에 사는 사용자 지정 NSView가 있습니다. 내가 operation의 모든 다른 유형을 시도했지만 이미지가 여전히 같은 NSSplitView의 나머지 절반의 위에 그립니다다른 뷰 위에 NSScrollView의 그림이 그려져 있습니다.

- (void)drawRect:(NSRect)dirtyRect { 
    NSGraphicsContext *ctx = [NSGraphicsContext currentContext]; 
    [ctx saveGraphicsState]; 

    // Rounded Rect 
    NSRect rect = [self bounds]; 
    NSRect pathRect = NSMakeRect(rect.origin.x + 3, rect.origin.y + 6, rect.size.width - 6, rect.size.height - 6); 
    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:pathRect cornerRadius:kDefaultCornerRadius]; 

    // Shadow 
    [NSShadow setShadowWithColor:[NSColor colorWithCalibratedWhite:0 alpha:0.66] 
         blurRadius:4.0 
          offset:NSMakeSize(0, -3)];  
    [[NSColor colorWithCalibratedWhite:0.196 alpha:1.0] set]; 
    [path fill]; 
    [NSShadow clearShadow]; 


    // Background Gradient 
    NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[UAColor darkBlackColor] endingColor:[UAColor lightBlackColor]]; 
    [gradient drawInBezierPath:path angle:90.0]; 
    [gradient release]; 


    // Image 
    [path setClip]; 
    NSRect imageRect = NSMakeRect(pathRect.origin.x, pathRect.origin.y, pathRect.size.height * kLargeImageRatio, pathRect.size.height); 
    [self.image drawInRect:imageRect 
        fromRect:NSZeroRect 
       operation:NSCompositeSourceAtop 
        fraction:1.0]; 

    [ctx restoreGraphicsState]; 

    [super drawRect:dirtyRect]; 
} 

:

enter image description here

사용자 정의보기는 다음 그리기 코드를 사용 ... NSScrollView에서 그림을 그리는 대신 나는 이것이 dirtyRect 대신에 모든 것을 그리는 것과 관련이 있다고 생각하지만, 나는 그림 코드를 편집하여 어떻게 그 부분을 그릴 수 있는지 모른다. dirtyRect에있다. 어떻게 그 위에 그리지 못하도록 할 수 있습니까? 아니면이 NSImage에 대해 더러운 사각형 만 그리시겠습니까?

답변

1

나는 마침내 그것을 얻었다. 아직 최적인지는 모르겠지만 성능 테스트를 수행 할 때는 알아낼 것입니다. 이제는 이미지 rect와 더러운 rect의 교차점을 NSIntersectionRect을 사용하여 파악한 다음 NSImage의 하위 부분을 찾아 drawInRect:fromRect:operation:fraction: 호출을 그립니다.

NSRect imageRect = NSMakeRect(pathRect.origin.x, pathRect.origin.y, pathRect.size.height * kLargeImageRatio, pathRect.size.height); 
    [self.image setSize:imageRect.size]; 

    NSRect intersectionRect = NSIntersectionRect(dirtyRect, imageRect); 
    NSRect fromRect = NSMakeRect(intersectionRect.origin.x - imageRect.origin.x, 
           intersectionRect.origin.y - imageRect.origin.y, 
           intersectionRect.size.width, 
           intersectionRect.size.height); 
    [self.image drawInRect:intersectionRect 
        fromRect:fromRect 
       operation:NSCompositeSourceOver 
        fraction:1.0]; 
: 여기

는 중요한 부분입니다
관련 문제