O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required