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

Challenge: Enforcing a Window’s Aspect Ratio

Create a new single-window application with one window. As the user resizes the window, make sure that the window always remains twice as tall as it is wide.

Here is the signature of the delegate method you will implement:

 ​ ​o​p​t​i​o​n​a​l​ ​f​u​n​c​ ​w​i​n​d​o​w​W​i​l​l​R​e​s​i​z​e​(​s​e​n​d​e​r​:​ ​N​S​W​i​n​d​o​w​,​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​t​o​S​i​z​e​ ​f​r​a​m​e​S​i​z​e​:​ ​N​S​S​i​z​e​)​ ​-​>​ ​N​S​S​i​z​e​

The first argument is the window that is being resized. The second argument describes the size that the user has asked for. The return value is the size that the user will get.

Hint: The second argument and the return value are typealiases for a struct: ...

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