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































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