为什么我的 NSPanel 没有正常的灰色背景?



我的应用程序在菜单栏中有一个图标。单击该图标时会显示一个NSPanel。但是为什么NSPanel没有像其他具有灰色背景NSWindow那样的背景颜色?我的NSPanel背景看起来像透明。 我的NSPanel来自.xib文件。我的代码如下:

(void)openPanel
{
NSLog(@"openPanel");
NSWindow *panel = self.panelController.window;
NSRect rect = [[[NSApp currentEvent] window] frame];
NSLog(@"rect.origin.x = %f",rect.origin.x);
NSLog(@"rect.origin.y = %f",rect.origin.y);
NSLog(@"rect.size.width = %f",rect.size.width);
NSLog(@"rect.size.height = %f",rect.size.height);
[panel setFrame:NSMakeRect(rect.origin.x, rect.origin.y-100, 200, 100) display:YES];
[NSApp activateIgnoringOtherApps:NO];
[panel makeKeyAndOrderFront:nil];
isPanelVisible = YES;
}

通常 NSPanels 是半透明的。有关更多信息,请参阅此处。如果您不想要半透明,您可以将自定义类下的IB中的NSPanel从NSPanel更改为NSWindow。

最新更新