DNB5brims
DNB5brims

Reputation: 30558

How to find the NSView position on the whole screen?

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.

Upvotes: 5

Views: 3309

Answers (1)

Renfei Song
Renfei Song

Reputation: 2960

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

Upvotes: 10

Related Questions