Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the NSView position on the whole screen?

Tags:

macos

swift

cocoa

I am writing an OS X application. I would like to find a NSView position on the whole screen. How can I find that position. I don't want this position related to the NSWindow, but the position on the whole screen. Is this possible to do so? Or I need to use NSWindow's location information to find that? Thanks.

like image 471
DNB5brims Avatar asked Feb 10 '23 00:02

DNB5brims


1 Answers

You can use NSWindow’s method -convertRectToScreen: to convert the rectangle to the screen coordinate system from the window’s coordinate system.

NSRect rectInScreen = [self.view.window convertRectToScreen:self.view.frame];

Documentation

like image 70
Renfei Song Avatar answered Mar 01 '23 21:03

Renfei Song