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.