1

I have a NSWindow where I set opaque attribute to NO. The problem is that when I put any view inside that window it's corners has blank pixels.

Everything works well when opaque attribue is left with YES value, however, window's corners are not rounded anymore. See picture:

I've created repository with simple example project at bitbucket: https://bitbucket.org/lukaszb/animationartifacts

Is there a way I can fix this (remain window's corners rounded and blank pixels not appearing)? Or should I try another solution (without setOapque:NO at NSWindow subclass)?

4

2 に答える 2

1

の Core Animation レイヤーを有効にしてみてくださいRoundedView。つまり、 を開いMainMenu.xibて選択RoundedViewし、[View Effects] タブ (一番右のタブ) で [Core Animation Layer] の下のビューを確認します。

または、プログラムで実行することもできます。たとえば、次のようにRoundedView追加します。

- (void)awakeFromNib {
    self.wantsLayer = YES;
    self.layer = [CALayer layer];
    self.layer.backgroundColor = [[NSColor blackColor] CGColor];
    self.layer.cornerRadius = RADIUS;
}

また、プロジェクト#import <QuartzCore/QuartzCore.h>に追加QuartzCore.frameworkします。すでに角が丸くなっているため、drawRectメソッドを削除できます。(実際には、その場所で使用するレギュラー用にこのレイヤーをセットアップするだけで、クラスCALayer全体を削除できます。)RoundedViewNSView

于 2012-11-04T19:08:26.147 に答える
0

NSView のサブクラスを作成し、その drawRect: メソッドで NSBezierPath を使用してカスタム描画を作成し、それをウィンドウのコンテンツ ビューとして設定できます。

于 2012-11-04T19:19:36.703 に答える