Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does an NSView's frame method return the wrong results?
    primarykey
    data
    text
    <p>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.</p> <p>The problem is that the frame method usually returns NSRects that are clearly wrong, from my perspective.</p> <p>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.</p> <p>Here is my awakeFromNib:</p> <pre><code>- (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; } </code></pre> <p>The results of this code look like this in the console:</p> <pre><code>in awakeFromNib the frame is 0, 0, 0, 0 the frame is 0, 1079230464, 0, 1078329344 </code></pre> <p>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 &amp; Position".</p> <p>In short, everything else about the program is working perfectly. It actually seems that the frame dimensions aren't set properly or something.</p> <p>Can somebody tell me how to retrieve the real frame information? Or at least explain the results I am seeing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload