2

内にあるカスタムNSViewがNSScrollViewありNSSplitViewます。カスタムビューは、次の図面コードを使用します。

- (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];
}

私はすべての異なるタイプを試しoperationましたが、画像はまだ他の半分の上に描かれてNSSplitViewいます:

ここに画像の説明を入力してください

…下に描画する代わりにNSScrollView。これは、すべてではなくすべてを描画することと関係があると思いますがdirtyRect、画像描画コードを編集して、にある部分のみを描画する方法がわかりませんdirtyRectどうすればそれが上に描画されないようにするか、このNSImageのダーティレクを描画するだけですか?

4

1 に答える 1

1

私はついにそれを手に入れました。まだ最適かどうかはわかりませんが、パフォーマンステストを行うときにわかります。を使用して、イメージrectとダーティrectの交点を把握し、次に、呼び出しのために描画するのNSIntersectionRectサブパートを把握する必要がありました。NSImagedrawInRect: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];
于 2011-02-25T00:18:45.140 に答える