objective-c - 如何确定哪个屏幕包含菜单栏?

标签 objective-c cocoa screen menubar

在 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/

相关文章:

objective-c - 将 string 转换为 int 会更改值

macos - 以编程方式更改 mac osx 上的代理

objective-c - 当新的推送通知到达时重置服务器端徽章计数器

ios - 为什么NSInteger在32位iOS上没有定义为long?

iphone - NSDictionary 或 NSObject 以 NSStrings 作为属性,哪个更好?

android - 通过从 Google Play 安装应用程序应用屏幕限制

android - 高分辨率屏幕的不同布局?

objective-c - 填充 Objective C 中的第二个表

iphone - 没有标题动画的pushViewController

iphone - 使用旧版 SDK 支持新 iPhone/iPod Touch 4 英寸显示屏