问题描述
我使用CGWindowListCopyWindowInfo获取所有窗口的列表。
I use CGWindowListCopyWindowInfo to get a list of all windows. It gives me the co-ordinates of each window based upon the origin being the top-left of the screen.
如果我使用NSWindow的setFrame,它会给出每个窗口的坐标,其基础是屏幕的左上角方法,坐标基于原点是屏幕的左下角。
If I use NSWindow's setFrame method, the co-ordinates on based upon the origin being the bottom-left of the screen.
什么是干净,可靠的方式转换从一个到另一个?
What's a clean, reliable way to convert from one to the other?
添加:通过干净可靠,我的意思是,无论用户是否有多个屏幕或正在使用空间,一定要工作。
Added: By clean and reliable, I mean, something sure to work regardless whether the user has multiple screens or is using Spaces. I figure there must be a known idiom using library APIs.
推荐答案
数学是相当可靠的: - )
Math is quite reliable :-)
yFromBottom = screenHeight - windowHeight - yFromTop
$ b b
主屏幕高度为
Main screen height is
[[[NSScreen screens] objectAtIndex:0] frame].size.height
这篇关于如何转换Cocoa协调从左上角==原点到左下角==原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!