0

並べて配置された 2 つの NSView があり、タイル化された画像から背景が作成されています。ビューに制約を追加してメイン ウィンドウのサイズを変更すると、タイル張りの背景画像が表示されなくなり、背景が黒くなります。

ここで何が欠けていますか?

#import "imageWellGraphics.h"

@implementation imageWellGraphics

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }
    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
    CGAffineTransform affineTransform = CGContextGetCTM(context);

    NSImage* image = [NSImage imageNamed: @"tile.png"];
    NSColor* imagePattern = [NSColor colorWithPatternImage: image];

    NSRect frame = NSInsetRect(self.bounds, 1, 1);

    NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRect:NSMakeRect(NSMinX(frame), NSMinY(frame), NSWidth(frame), NSHeight(frame))];
    [NSGraphicsContext saveGraphicsState];
    CGContextSetPatternPhase(context, NSMakeSize(affineTransform.tx, affineTransform.ty));
    [imagePattern setFill];
    [rectanglePath fill];
    [NSGraphicsContext restoreGraphicsState];
}

@end
4

2 に答える 2

0

この行をdrawrectメソッド内に含めてチェックします:-

[super drawRect:dirtyRect];
于 2013-10-31T05:34:10.290 に答える