I'm just playing around with OSX app dev. I'm totally noob. I thought it is straight forward like iOS app dev. But after a few days of going at this, it seems it is not that easy.
Here's what I'm trying to do. I have a NSWindow. In it in which I put an Image Well (wth with the naming? lol) Well "Image Well", it is an NSImageView (no pun intended).
So I just want the NSImageView's frame to resize following the NSWindow's size. It's that simple.
Here's what I did that is NOT working:
NSImageView as imageView.
write the delegate method NSWindowDelegate method of NSWindow windowDidResize and windowDidResize: and just resize the framesize of imageView frame of the image view in it. Code: (The NSImageView is in a property called imageView.)
- (void)windowDidResize:(NSNotification *)notification {
// NSLog(@"resized");
NSRect zWindowRect = [[self window]frame];
NSRect zContentRect = [[self window]contentRectForFrameRect:zWindowRect];
[self.imageView setFrameSize:NSMakeSize(zContentRect.size.width,
zContentRect.size.height)];
[self.imageView setNeedsDisplay:YES];
}
This method is called (tested that with NSLog()
), however the NSImageView
just stays there with the original size. I checked that the IBOutlet
connection is OK.
What gives? Why won't the NSImageView
resize?
Ok. This is becoming a habit. Answering my own question again.
It seems that this behaviour is due to the "Auto Layout" feature of the Interface Builder.
To fix it, just disable "Auto Layout" in the MainMenu.xib. SEE HERE FOR EXPLANATIONS
In case the site expires: just click on MainMenu.xib, then go to the first tab, File, in the Utilities panel of XCode. And there should be a "Use Auto Layout" checkbox next to it. Uncheck it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With