Rifat
Rifat

Reputation: 1888

find application position relative to screen point macOS swift

Trying to find applications current position in X Y coordinate. For example: An application has starting point(X,Y) + Hight, Width. How to find its starting point as CGPoint or X Y onscreen values?

Current trying with view.bounds :

class ViewController: NSViewController {

var testPoint = CGPoint.zero;

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    //testPoint = view.bounds.height //rect
    //if possible following:
   //testPoint =  CGPoint(x: view.window?.frame.origin.x , y: view.window?.frame.origin.y) 
    print(testPoint)
  }
}

Upvotes: 1

Views: 467

Answers (2)

vadian
vadian

Reputation: 285260

In viewWillAppear or viewDidAppear ask the window of the view for the origin of its frame

override func viewWillAppear() {
    super.viewWillAppear()
    print(view.window?.frame.origin)
}

Upvotes: 2

olha
olha

Reputation: 2272

You should use NSWindow API, particularly NSWindow.frameRect.

Upvotes: 0

Related Questions