I occasionally want to change an NSView's dimensions programmaticaly. To do this, it is helpful to get the dimensions of various views, adjust them relative to each other, and then use setFrame: to reposition.
The problem is that the frame method usually returns NSRects that are clearly wrong, from my perspective.
I have a program with an NSPanel set up in Interface Builder and various connections to my main program. To test the NSRects returned by frame, I opened the panel in my application's awakeFromNib: method, retrieved some NSRects, and printed them to the console.
Here is my awakeFromNib:
- (void)awakeFromNib {
NSLog(@"in awakeFromNib");
[self showPrefsSheet:self]; //this is the prefs sheet with the controls of interest
//note that it does indeed pop up and is displayed
originalFrame = [aTextView frame];
NSLog(@"the frame is %d, %d, %d, %d", originalFrame.origin.x, originalFrame.origin.y, originalFrame.size.width, originalFrame.size.height);
originalFrame = [aButton frame];
NSLog(@"the frame is %d, %d, %d, %d", originalFrame.origin.x, originalFrame.origin.y, originalFrame.size.width, originalFrame.size.height);
return;
}
The results of this code look like this in the console:
in awakeFromNib
the frame is 0, 0, 0, 0
the frame is 0, 1079230464, 0, 1078329344
Note that (i) the panel and both controls are displayed on the screen; (ii) I know for a fact that the outlets are properly connected, because I can do things to the controls programmatically and have them work; (iii) interface builder shows correct frame sizes in the Inspector under "Size & Position".
In short, everything else about the program is working perfectly. It actually seems that the frame dimensions aren't set properly or something.
Can somebody tell me how to retrieve the real frame information? Or at least explain the results I am seeing?