Problem with Manual Layout in Test App


Dave
 

Manual Layout on Mac using the “resizeWithOldSuperviewSize” way of doing things.

Hi,

I have a simple app which works 99% of the time, however every now and then it screws up. The app just has 4 views, all with a different background colour. All I want to happen for one view to track the bounds of the Window as the user resizes it and for all the other views to be inset within their superview by 20,20 pixels. 

The storyboard file (Main.storyboard) has Auto Layout tuned off in IB.

The App has a View Hierarchy as follows:

LTWSimpleWindowController
LTWSimpleWindow

LTWSimpleViewController
LTWWindowTrackerView .view property
LTWSimpleBaseView
LTWSimpleGreenView
LTWSimpleBlueView

The above are Class names in the project.

LTWSimpleWindow
Has ContentSize and MinSize set to 100,100 in IB.


LTWSimpleViewController
Has no real code, but logs the viewDidLoad method.


LTWWindowTrackerView
This view is set as the root view of the view controller (e.g. the .view property).
Has background color set to Red.


LTWSimpleBaseView
Has background color set to Black.
This view just sets its Frame Rect to the superview bounds Rect - 
self.frame = self.superview.bounds 
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;


LTWSimpleGreenView
Has background color set to Green.
This view just sets its Frame Rect to the an inset of the superview bounds - 
self.frame = NSInsetRect(self.superview.bounds,20,20);
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;

LTWSimpleBlueView
Has background color set to Blue.
This view just sets its Frame Rect to the an inset of the superview bounds - 
self.frame = NSInsetRect(self.superview.bounds,20,20);
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;
 

The initWithCoder: method is overridden and the autoresizesSubviews and translatesAutoresizingMaskIntoConstraints properties are set here.
The resizeWithOldSuperviewSize: method is overridden and the frame is set here.
The isFlipped method is overridden and returns YES,

Super is called in both methods.

The NIB is set with the views initially in place, e.g. inset my 20,20 in their parent views.

I’m really confused as to what to set as the auto-resizing mask of all the views, at present its set as follows:

LTWWindowTrackerView has the markers on the outside edge of the view are set (Top, Left, Bottom, Right) and the ones on the inside of the view are off. in IB

All the other views have their autoresize masks off, e.g. no marks set in IB.

Is this correct?

When I run the App, the Window displays ok initially, if I resize the window *slowly* then it works ok. If however I make the window really big and then close it up to the minimum size *very-quickly* then  LTWSimpleBlueView and LTWSimpleGreenView are not positioned correctly. 

I’ve attached 3 images (not sure if they will get through), showing the initial window, the big window and the result of making it small again very quickly.

I’ve more or less got everything else working but just want to sort out this last problem and its driving me nuts! I can’t seem to find any working example of using the  “resizeWithOldSuperviewSize” way of doing things.

I can send the Test app if anyone wants to take a look.

All the Best
Dave
































Keary Suska
 

I am not sure if you are just trying a test case here, but what you are shooting for can be done with just autoresize mask. Comment out all the code and add the vertical and horizontal resizing options (the inner “cross”). Set these for all views (i.e. all masks on). You see in IB that you can resize the view at any speed and all views retain their spacing.

Other notes: I wouldn’t set autoresizesSubviews or translatesAutoresizingMaskIntoConstraints in code. Set it in IB and it is done. Setting them might cause unintended side effects. Also, do you call super? I wouldn’t if you want to control resizing all by yourself. Do you log before/after frame sizes both in super view and subview, to make sure they look like values you expect? You might also want to compare these values with just using autoresize mask to see if there are any differences.

I will look at your project if you like.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

On Oct 4, 2018, at 7:07 AM, Dave <dave@...> wrote:

Manual Layout on Mac using the “resizeWithOldSuperviewSize” way of doing things.

Hi,

I have a simple app which works 99% of the time, however every now and then it screws up. The app just has 4 views, all with a different background colour. All I want to happen for one view to track the bounds of the Window as the user resizes it and for all the other views to be inset within their superview by 20,20 pixels.

The storyboard file (Main.storyboard) has Auto Layout tuned off in IB.

The App has a View Hierarchy as follows:

LTWSimpleWindowController
LTWSimpleWindow

LTWSimpleViewController
LTWWindowTrackerView .view property
LTWSimpleBaseView
LTWSimpleGreenView
LTWSimpleBlueView

The above are Class names in the project.

LTWSimpleWindow
Has ContentSize and MinSize set to 100,100 in IB.


LTWSimpleViewController
Has no real code, but logs the viewDidLoad method.


LTWWindowTrackerView
This view is set as the root view of the view controller (e.g. the .view property).
Has background color set to Red.


LTWSimpleBaseView
Has background color set to Black.
This view just sets its Frame Rect to the superview bounds Rect -
self.frame = self.superview.bounds
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;


LTWSimpleGreenView
Has background color set to Green.
This view just sets its Frame Rect to the an inset of the superview bounds -
self.frame = NSInsetRect(self.superview.bounds,20,20);
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;

LTWSimpleBlueView
Has background color set to Blue.
This view just sets its Frame Rect to the an inset of the superview bounds -
self.frame = NSInsetRect(self.superview.bounds,20,20);
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;


The initWithCoder: method is overridden and the autoresizesSubviews and translatesAutoresizingMaskIntoConstraints properties are set here.
The resizeWithOldSuperviewSize: method is overridden and the frame is set here.
The isFlipped method is overridden and returns YES,

Super is called in both methods.

The NIB is set with the views initially in place, e.g. inset my 20,20 in their parent views.

I’m really confused as to what to set as the auto-resizing mask of all the views, at present its set as follows:

LTWWindowTrackerView has the markers on the outside edge of the view are set (Top, Left, Bottom, Right) and the ones on the inside of the view are off. in IB

All the other views have their autoresize masks off, e.g. no marks set in IB.

Is this correct?

When I run the App, the Window displays ok initially, if I resize the window *slowly* then it works ok. If however I make the window really big and then close it up to the minimum size *very-quickly* then LTWSimpleBlueView and LTWSimpleGreenView are not positioned correctly.

I’ve attached 3 images (not sure if they will get through), showing the initial window, the big window and the result of making it small again very quickly.

I’ve more or less got everything else working but just want to sort out this last problem and its driving me nuts! I can’t seem to find any working example of using the “resizeWithOldSuperviewSize” way of doing things.

I can send the Test app if anyone wants to take a look.

All the Best
Dave


<PastedGraphic-1.png>

<PastedGraphic-2.png>

<PastedGraphic-3.png>




























Dave
 

Hi Keary,

Thanks for taking the time to look at this.

On 4 Oct 2018, at 16:49, Keary Suska <cocoa-dev@...> wrote:

I am not sure if you are just trying a test case here, but what you are shooting for can be done with just autoresize mask. Comment out all the code and add the vertical and horizontal resizing options (the inner “cross”). Set these for all views (i.e. all masks on). You see in IB that you can resize the view at any speed and all views retain their spacing.
Yes, just a test case here, in the real app, it does a lot of elaborate things.


Other notes: I wouldn’t set autoresizesSubviews or translatesAutoresizingMaskIntoConstraints in code. Set it in IB and it is done. Setting them might cause unintended side effects. Also, do you call super? I wouldn’t if you want to control resizing all by yourself. Do you log before/after frame sizes both in super view and subview, to make sure they look like values you expect? You might also want to compare these values with just using autoresize mask to see if there are any differences.
I’ve tried various combinations of settings on this, but not found the magic one yet.

I will look at your project if you like.
Sent offline.

Thanks a lot
All the Best
Dave



Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

On Oct 4, 2018, at 7:07 AM, Dave <dave@...> wrote:

Manual Layout on Mac using the “resizeWithOldSuperviewSize” way of doing things.

Hi,

I have a simple app which works 99% of the time, however every now and then it screws up. The app just has 4 views, all with a different background colour. All I want to happen for one view to track the bounds of the Window as the user resizes it and for all the other views to be inset within their superview by 20,20 pixels.

The storyboard file (Main.storyboard) has Auto Layout tuned off in IB.

The App has a View Hierarchy as follows:

LTWSimpleWindowController
LTWSimpleWindow

LTWSimpleViewController
LTWWindowTrackerView .view property
LTWSimpleBaseView
LTWSimpleGreenView
LTWSimpleBlueView

The above are Class names in the project.

LTWSimpleWindow
Has ContentSize and MinSize set to 100,100 in IB.


LTWSimpleViewController
Has no real code, but logs the viewDidLoad method.


LTWWindowTrackerView
This view is set as the root view of the view controller (e.g. the .view property).
Has background color set to Red.


LTWSimpleBaseView
Has background color set to Black.
This view just sets its Frame Rect to the superview bounds Rect -
self.frame = self.superview.bounds
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;


LTWSimpleGreenView
Has background color set to Green.
This view just sets its Frame Rect to the an inset of the superview bounds -
self.frame = NSInsetRect(self.superview.bounds,20,20);
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;

LTWSimpleBlueView
Has background color set to Blue.
This view just sets its Frame Rect to the an inset of the superview bounds -
self.frame = NSInsetRect(self.superview.bounds,20,20);
self.autoresizesSubviews = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;


The initWithCoder: method is overridden and the autoresizesSubviews and translatesAutoresizingMaskIntoConstraints properties are set here.
The resizeWithOldSuperviewSize: method is overridden and the frame is set here.
The isFlipped method is overridden and returns YES,

Super is called in both methods.

The NIB is set with the views initially in place, e.g. inset my 20,20 in their parent views.

I’m really confused as to what to set as the auto-resizing mask of all the views, at present its set as follows:

LTWWindowTrackerView has the markers on the outside edge of the view are set (Top, Left, Bottom, Right) and the ones on the inside of the view are off. in IB

All the other views have their autoresize masks off, e.g. no marks set in IB.

Is this correct?

When I run the App, the Window displays ok initially, if I resize the window *slowly* then it works ok. If however I make the window really big and then close it up to the minimum size *very-quickly* then LTWSimpleBlueView and LTWSimpleGreenView are not positioned correctly.

I’ve attached 3 images (not sure if they will get through), showing the initial window, the big window and the result of making it small again very quickly.

I’ve more or less got everything else working but just want to sort out this last problem and its driving me nuts! I can’t seem to find any working example of using the “resizeWithOldSuperviewSize” way of doing things.

I can send the Test app if anyone wants to take a look.

All the Best
Dave


<PastedGraphic-1.png>

<PastedGraphic-2.png>

<PastedGraphic-3.png>






























Dave
 

Hi,

I’ve added logging to the resizeWithOldSuperviewSize: method (see below). Notice that LTWWindowTrackerView:: resizeWithOldSuperviewSize is never called, not sure why, but if I remove the auto-resize mask from it, it calls it, still doesn’t work though.



The first logging Group is the window at its big size, I then quickly resize it to the window Minumum and last Group shows the rectangles as being ok, however on the screen it looks like the attached image.



Cheers
Dave

—————————————————————————————

Window at Big Size:

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {1811, 1018}}  Frame {{20, 20}, {1771, 978}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {1851, 1058}}  Frame {{20, 20}, {1811, 1018}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {1851, 1058}}  Frame {{0, 0}, {1851, 1058}}

----------------------------------------------------------

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {1788, 1018}}  Frame {{20, 20}, {1748, 978}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {1828, 1058}}  Frame {{20, 20}, {1788, 1018}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {1828, 1058}}  Frame {{0, 0}, {1828, 1058}}

----------------------------------------------------------

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {1743, 980}}  Frame {{20, 20}, {1703, 940}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {1783, 1020}}  Frame {{20, 20}, {1743, 980}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {1783, 1020}}  Frame {{0, 0}, {1783, 1020}}

----------------------------------------------------------

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {1618, 925}}  Frame {{20, 20}, {1578, 885}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {1658, 965}}  Frame {{20, 20}, {1618, 925}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {1658, 965}}  Frame {{0, 0}, {1658, 965}}

----------------------------------------------------------

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {1405, 819}}  Frame {{20, 20}, {1365, 779}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {1445, 859}}  Frame {{20, 20}, {1405, 819}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {1445, 859}}  Frame {{0, 0}, {1445, 859}}

----------------------------------------------------------

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {1159, 691}}  Frame {{20, 20}, {1119, 651}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {1199, 731}}  Frame {{20, 20}, {1159, 691}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {1199, 731}}  Frame {{0, 0}, {1199, 731}}

----------------------------------------------------------

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {187, 136}}  Frame {{20, 20}, {147, 96}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {227, 176}}  Frame {{20, 20}, {187, 136}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {227, 176}}  Frame {{0, 0}, {227, 176}}

—————————————————————————————
Window at Smallest Size:

LTWSimpleBlueView: Superview Bounds: {{0, 0}, {60, 60}}  Frame {{20, 20}, {20, 20}}
LTWSimpleGreenView: Superview Bounds: {{0, 0}, {100, 100}}  Frame {{20, 20}, {60, 60}}
LTWSimpleBaseView: Superview Bounds: {{0, 0}, {100, 100}}  Frame {{0, 0}, {100, 100}}