- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
documentation [NSScreen mainscreen]
具有误导性。
The main screen is not necessarily the same screen that contains the menu bar or has its origin at (0, 0). The main screen refers to the screen containing the window that is currently receiving keyboard events. It is the main screen because it is the one with which the user is most likely interacting.
我尝试:
printf( "%p \n", [NSScreen mainScreen]);
for( NSScreen* sc in [NSScreen screens] ) {
NSRect f = [sc frame];
printf("%p %f %f %f %f \n", sc, f.origin.x, f.origin.y, f.size.width,f.size.height );
}
我将我的 Xcode 窗口拖到我的原生 MacBook 显示器上,确保它有键盘焦点,然后执行:
0x1006aaac0
0x1006aaac0 0.000000 0.000000 2560.000000 1440.000000
0x1006ab3d0 0.000000 -800.000000 1280.000000 800.000000
现在我将它拖到我的 LCD 上,确保它有键盘焦点,然后执行:
0x1005a15e0
0x1005a15e0 0.000000 0.000000 2560.000000 1440.000000
0x1005a64c0 0.000000 -800.000000 1280.000000 800.000000
所以 [NSScreen mainscreen]
每次都识别 LCD(带有菜单栏的那个)。
看来 [NSScreen mainscreen]
,与文档相反,实际上确实产生了带有菜单栏的屏幕。
有人愿意确认这是文档错误吗?
最佳答案
Xcode的窗口的位置跟它有什么关系呢?查询它的程序可能不是 Xcode 本身,而是您的应用程序。
无论如何,这受“系统偏好设置”>“任务控制”>“显示有单独的空间”的影响。另请参阅 10.9 AppKit release notes :
Spaces and Multiple Screens
In 10.9, we have added a feature where each screen gets its own set of spaces, and it is possible to switch between spaces on one screen without perturbing the spaces on the other screens. In this mode, a fullscreen window uses one screen, and leaves the contents of any other screens unchanged.
Each screen now has its own menu bar, and it is possible to show the Dock on any screen, provided you have the Dock set to “Position on Bottom”.
The menu bar has an active appearance on the active screen, which is typically the screen containing the key window. Menu bars on other screens have an inactive appearance.
In this mode, it is desirable for new windows to open on the active screen. In support of this model, +[NSScreen mainScreen] now returns the active screen, which is slightly different than its prior behavior of returning the screen containing the keyWindow, if any, and the zero screen otherwise.
A window restored at app launch through -restoreStateWithCoder: will return to its previous location, independent of active screen. A window positioned using -setFrameAutosaveName: will prefer the active display.
This feature can be disabled by unchecking the preference named “Displays have Separate Spaces” in the Mission Control preference pane in System Preferences. This setting only takes effect after logging out and back in, or restarting. NSScreen has API to query whether the separate space feature is enabled:
+ (BOOL)screensHaveSeparateSpaces NS_AVAILABLE_MAC(10_9);
When this feature is enabled, windows may not visibly span displays. A window will get assigned to the display containing the majority of its geometry if programmatically positioned in a spanning position. A window will get assigned to the display containing the mouse if the window is moved by the user. A window clips to the edge of the display, whether or not there is another adjacent display.
遗憾的是,许多重要信息仅在发行说明中。它并不总是包含在主要文档中。
请注意对 +mainScreen
的“旧”行为的稍微不同的解释:
… its prior behavior of returning the screen containing the keyWindow, if any, and the zero screen otherwise.
考虑到,对于一个不活动的应用程序或没有窗口的应用程序,-[NSApplication keyWindow]
将是 nil
,因此 +mainScreen
将返回零屏幕。因此,引用您引用的文档:
The main screen refers to the screen containing the window that is currently receiving keyboard events.
没有说的是“在调用应用程序中”。
无论如何,如果您想要的是主显示器,即 (0, 0) 处的显示器,只需使用 NSScreen.screens[0]
。
关于objective-c - `[NSScreen mainscreen]` 误导文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56268640/
我必须通过向 td 添加一个名为 active 的类来突出显示多个单元格。此类将更改边框颜色以突出显示单元格。 这里的问题是,如果选择了特定单元格的顶部、右侧、底部和左侧单元格,那么中心单元格将看起来
我已经按照以下步骤完成: https://www.youtube.com/watch?v=88dmtleVywk&list=PLlrATfBNZ98dC-V-N3m0Go4deliWHPFwT&ind
我有三个文章标签,每个标签都有 1 个部分,我需要对其进行动画显示,即从 0px 到任何 px 的高度。每篇文章都有一个 ID 什么是最有效的方法来为每篇文章设置点击事件,而无需为每个单独的 ID 编
我试图理解以下程序的奇怪行为。很明显,在全局变量“bug”的定义过程中发生了溢出,但是程序在无辜计算1.0+2.0的过程中抛出了浮点异常。 #include #include #include
当我尝试以下错误代码时: not_float = [1, 2, 3] "{:.6f}".format(not_float) 我收到以下误导性 ValueError: ValueError: Unkno
我是一名优秀的程序员,十分优秀!