[Macos]init Windows position--Method Two: Code implementation

Source: Internet
Author: User

Create a new file that inherits from the Nswindowcontroller class Windowcontroller.

Select class:

Write code in Windowcontroller.swift.

Add the code inside the Windowdidload:

If let window = window, screen = window.screen {let            offsetfromleftofscreen:cgfloat =            Offsetfromtopofscree N:cgfloat =            Screenrect = screen.visibleframe            print (screenrect) let            neworiginy = Cgrectgetmaxy ( Screenrect)-Window.frame.height-offsetfromtopofscreen            //Set window lower left corner coordinates            window.setframeorigin (nspoint (x: Offsetfromleftofscreen, Y:neworiginy)        }

Running we can see:

There's another one.

We can see that screenrect is the screen size!

Then there is a problem, the new window will be completely overlapping with the original window, this is very unfriendly, how to solve it?

Adding a piece of code is OK:

Required init? (Coder:nscoder) {        super.init (coder:coder)        //Set new window pop-up waterfall        Shouldcascadewindows = True    }

Run it again to see:

[Macos]init Windows position--Method Two: Code implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.