Re: How to Correctly Resize Views with Manual Layout


Andy Lee
 

Two quick comments:

- You want to set the subview's frame relative to the superview's bounds, not its frame.
- You might want to experiment with a scratch app before making a lot of code changes at once in your existing app. Or, if possible, make your code changes incrementally, relaunch the app, fiddle with window size, and see if the changes look right.

--Andy

On Wed, Sep 26, 2018, at 8:55 AM, Dave wrote:
Hi All,

I’ve started move over to using the correct Manual Layout Methods as per
my recent posts. The methods are:

resizeWithOldSuperviewSize


WindowTrackerView .view Property
SubviewA

All views have isFlipped override and returning YES.


Given that I want SubviewA to be inset 10 pixels from the top, left and
right of the Superview and bottom to be the same as the superview, what
code do I need to write?


For instance would the following work:

-(void) resizeWithOldSuperviewSize:(NSSize) theOldSuperviewSize
{
NSRect myRect;

[super resizeWithOldSuperviewSize: theOldSuperviewSize];

myRect.origin = self.superview.frame.origin.x + 10;
myRect.origin = self.superview.frame.origin.y + 10;
myRect.size.width = self.superview.frame.size.width - (10 *2);
myRect.size.height = self.superview.frame.size.height - 10;
self.frame = myRect;
}

I just want to be sure I’m on the right track before I start changing
loads of code.

If anyone knows of a working example of using these methods, I’d be
really grateful if they could point me to it!

Thanks in advance for any help.

All the Best
Dave



Join cocoa@apple-dev.groups.io to automatically receive all group messages.