在 Cocoa 中,当计算机有多个屏幕时,如何确定哪个屏幕保存菜单栏?
这是我到目前为止所拥有的:
NSArray * screens = [NSScreen screens];
NSScreen * mainScreen = [screens objectAtIndex:0];
if ([screens count] > 1)
{
for (NSScreen * screen in screens)
{
if (/* screen == the screen that holds the menubar */)
{ mainScreen = screen; break; }
}
}
NSLog(@"the main screen is: %@", mainScreen);
注意:我尝试使用[NSScreen mainScreen]
,但这只是返回当前事件窗口所在的屏幕。如果我的应用程序中没有打开其他窗口,它只会返回具有菜单栏的屏幕。
最佳答案
来自NSScreen文档:
The screen containing the menu bar is always the first object (index 0) in the array returned by the screens method.
所以你的变量 mainScreen 已经包含它了。
关于objective-c - 如何确定哪个屏幕包含菜单栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3163343/