如何转换Cocoa协调从左上角==原点到左下角==原点 [英] How do I convert Cocoa co-ords from top left == origin to bottom left == origin

查看:298
本文介绍了如何转换Cocoa协调从左上角==原点到左下角==原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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协调从左上角==原点到左下角==原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆