Views, Rectangles, and Coordinate Systems

When a window appears on screen, Cocoa must position each view in the window’s hierarchy. To know how to position a view, Cocoa needs two pieces of information:

  • the origin, or position of the lower-left corner of the view in relation to the lower-left corner of its superview

  • the size of the rectangle occupied by the view

frame

The position and size of the view are specified by its frame property, which is an NSRect.

 ​ ​s​t​r​u​c​t​ ​N​S​R​e​c​t​ ​{​
 ​ ​ ​ ​ ​ ​v​a​r​ ​o​r​i​g​i​n​:​ ​N​S​P​o​i​n​t​
 ​ ​ ​ ​ ​ ​v​a​r​ ​s​i​z​e​:​ ​N​S​S​i​z​e​
 ​ ​}​

The origin of the frame specifies the position of the lower-left corner as the offset from the superview’s lower-left ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.