4

NSWindow (メイン ウィンドウ) と子ウィンドウ (NSWindowBelowメイン ウィンドウに配置) があり、NSTextView. 子ウィンドウには、タイトル バーも影も透明もありません。
子ウィンドウを設定して透明にするために使用するコードは次のとおりです。

- (id) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag{
    if (![super initWithContentRect: contentRect styleMask:NSBorderlessWindowMask backing: bufferingType defer:NO]) return nil;

    [self setBackgroundColor: [NSColor clearColor]];
    [self setOpaque:NO];

    return self;
}

しかし、その中のテキストを選択しようとすると、次のようになります (子ウィンドウの上の黒いものがメイン ウィンドウです):選択範囲が青ではないため、フォーカスされていない
ここに画像の説明を入力
ようです。NSTextViewを呼び出してみまし[[_childWindow textView] becomeFirstResponder];たが、結果は同じです。もう1つのことは、スクロールすると、非常に遅くて「壊れやすい」ことがあるということです。

これを引き起こしている原因とそれを修正する方法について何か考えはありますか? ウィンドウにタイトルバーがないためだと思いますが、よくわかりません。ありがとう!

4

1 に答える 1

2

NSWindow ドキュメントから:

canBecomeKeyWindow
Indicates whether the window can become the key window.

- (BOOL)canBecomeKeyWindow
Return Value
YES if the window can become the key window, otherwise, NO.

Discussion
Attempts to make the window the key window are abandoned if this method returns 
NO. The NSWindow implementation returns YES if the window has a title bar or a 
resize bar, or NO otherwise.

上書き-canBecomeKeyWindowして YES を返してみてください。

于 2013-05-15T19:51:12.100 に答える