Cocoa programming question
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
- (NSSize)windowWillResize
NSWindow *)sender
tosize
NSSize)frameSize;
method. So far so good. I have the following code in my .m file
@implementation AppController
- (NSSize)windowWillResize
NSWindow *)sender toSize
NSSize)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.)
Code:
- (NSSize)windowWillResize

tosize

method. So far so good. I have the following code in my .m file
Code:
@implementation AppController
- (NSSize)windowWillResize


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