Cocoa programming question

Jump to First Reply
Posted:
in Genius Bar edited January 2014
I'm working on the challenge for Chapter 5 of "Cocoa Programming for Mac OS X". They want you to make a window in IB and set the behavior on resizing to always have the window be twice as high as it is wide. You are supposed to create a delegate object for the window and use the

Code:


- (NSSize)windowWillResizeNSWindow *)sender

tosizeNSSize)frameSize;







method. So far so good. I have the following code in my .m file

Code:




@implementation AppController



- (NSSize)windowWillResizeNSWindow *)sender toSizeNSSize)frameSize

{

NSSize theSize;

int width;

theSize = NSMakeSize(width, width * 2);

return theSize;

}











It works if I set a constant value for width, but then the window just resizes to that one size when you resize it.



I guess what I need is a method that returns the window's current width. Then I could set the width to that, and the window would maintain the proper ratio while resizing.



Any suggestions on how to do this?



(I realize setting the aspect ratio is a better way of doing this, but the point of the exercise was to use helper objects and delegates.)

Comments

  • Reply 1 of 2
    spotcatbugspotcatbug Posts: 195member
    Erm... I'm no Cocoa guru, but doesn't that toSize parameter have the width you're looking for?
     0Likes 0Dislikes 0Informatives
  • Reply 2 of 2
    You are a genius with a capital J! I changed the code to look like this.



    Code:




    @implementation AppController



    - (NSSize)windowWillResizeNSWindow *)sender toSizeNSSize)frameSize

    {

    NSSize theSize;

    theSize = NSMakeSize(frameSize.width, frameSize.width * 2);

    return theSize;

    }











    The answer was right under my nose along. Thanks for the help.
     0Likes 0Dislikes 0Informatives
Sign In or Register to comment.