Why does the NSView framework method return incorrect results?

Sometimes I want to change NSView settings programmatically. To do this, it is useful to get the sizes of the different views, adjust them relative to each other, and then use setFrame: move.

The problem is that the frame method usually returns NSRects that are clearly wrong from my point of view.

I have a program with NSPanel configured in Interface Builder, and various connections to my main program. To check the NSRects returned by the frame, I opened a panel in my awakeFromNib application: a method, extracted some NSRects, and printed them on 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 are as follows in the console:

in awakeFromNib
the frame is 0, 0, 0, 0
the frame is 0, 1079230464, 0, 1078329344

, (i) ; (ii) , , - ; (iii) " ".

, . , - .

- , ? , , , ?

+3
2

- , % d. ().

NSLog :

@"the frame is %f, %f, %f, %f"

:

, rects:

#define RECTLOG(rect)    (NSLog(@""  #rect @" x:%f y:%f w:%f h:%f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height ));

:

RECTLOG([aTextView frame]);
+9

NSRect , , .

, ( ), , :

NSLog(@"frame - %@", NSStringFromRect([view frame]));

. :

NSStringFromSize
NSStringFromPoint
NSStringFromRange

..

+4

Source: https://habr.com/ru/post/1712601/


All Articles