In Objective-C (OS X), is the “global display” coordinate space used by Quartz Display Services the same as Cocoa's “screen” coordinate space?

[亡魂溺海] 提交于 2019-12-03 05:59:30

Quartz uses a coordinate space where the origin (0, 0) is at the top-left of the primary display. Increasing y goes down.

Cocoa uses a coordinate space where the origin (0, 0) is the bottom-left of the primary display and increasing y goes up.

You can convert a window's frame from Cocoa to Quartz like so:

NSRect frame = window.frame;
frame.origin.y = NSMaxY(NSScreen.screens[0].frame) - NSMaxY(frame);
CGRect quartzRect = NSRectToCGRect(frame);

Note: you don't use the window's -screen, you always use the primary screen.

This is for a rect in window coordinates. For a rect in a view, first convert from view coordinates to window coordinates using -[NSView convertRect:toView:] with nil as the destination view signifying the window. This would do the right thing for someView.bounds but not for someView.frame, since a view's frame is in the superview's coordinate system.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!