NSView圆角绘制错误

时间:2017-04-13 08:44:07

标签: objective-c macos drawing nsview rounded-corners

我在OSX上,XCode 8.2,Objective-C

我有一个带背景图片的窗口:

self.window.titleVisibility = NSWindowTitleHidden;
self.window.titlebarAppearsTransparent = YES;
self.window.styleMask |= NSFullSizeContentViewWindowMask;
self.window.movableByWindowBackground = YES;
self.window.opaque = NO;       
self.window.backgroundColor = [NSColor colorWithPatternImage:[NSImage imageNamed:@"background.jpg"]]];

在那个窗口中,我有一个NSTabViewController。在其中一个NSTabViews上,我画了一个带圆角的NSView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer = _layer;   // strangely necessary
        self.wantsLayer = YES;
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 10.0;
    }
    return self;
}

我的问题是,即使角落是圆的,仍然可以看到明亮的白色角落。

enter image description here

这里的答案(rounded corners on NSView using NSBezierPath are drawn badly)对我没有用,因为我有一张背景图片 - 虽然它没有背景图片。但我想保留该图像,因为可以通过单击其背景来拖动窗口。

我还尝试使用NSImageView作为我的背景图片,将其移到后面并覆盖它的mouseDownCanMoveWindow方法。这也适用于拖动,但仍不适用于角落绘图。

任何帮助表示赞赏

0 个答案:

没有答案