Contents

constrainFrameRect(_:to:)

Modifies and returns a frame rectangle so that its top edge lies on a specific screen.

Declaration

func constrainFrameRect(_ frameRect: NSRect, to screen: NSScreen?) -> NSRect

Parameters

  • frameRect:

    The proposed frame rectangle to adjust.

  • screen:

    The screen on which the top edge of the window’s frame is to lie.

Return Value

The adjusted frame rectangle.

Discussion

If the window is resizable and the window’s height is greater than the screen height, the rectangle’s height is adjusted to fit within the screen as well. The rectangle’s width and horizontal location are unaffected. You shouldn’t need to invoke this method yourself; it’s invoked automatically (and the modified frame is used to locate and set the size of the window) whenever a titled NSWindow object is placed onscreen and whenever its size is changed.

Subclasses can override this method to prevent their instances from being constrained or to constrain them differently.

See Also

Sizing Windows