Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoresizing not working in iOS11 / XCode 9

It appears that the Autoresizing of views is no longer reliably working when building for iOS11 with XCode 9.

The layout of several views end up with the positioning of controls as they are in the XIB, but the appropriate resizing has not happened. This has been working fine in iOS10, and works with our old app running in iOS11. However, rebuilding the app the positioning and sizing fails.

Has something changed that impacts the use of autoresizingmask?

Is there a way to automatically convert from AutoResizing to AutoLayout and Constraints?

Edit: The controls that are giving trouble are the UINavigationBar and UIToolBar.

like image 998
Jim Leask Avatar asked Sep 18 '17 14:09

Jim Leask


2 Answers

I'm working on this same issue today: one thing that has worked in some cases is swapping out for similar (but not identical) mask values. For example, one of our views didn't work with UIViewAutoresizingFlexibleHeight but it works with UIViewAutoresizingFlexibleBottomMargin.

I'm not aware of an automatic way to upgrade to AutoLayout - I actually use AutoLayout a lot in other projects, and the conceptual basis is pretty different...

I'll edit this answer if I find anything better.

like image 81
John Nimis Avatar answered Oct 04 '22 18:10

John Nimis


Same issue here. As mentioned by @John Nimis playing with masks sometime seems to solve the problem. For example, when we had both top and bottom masks (UIViewAutoresizingFlexibleTopMargin| UIViewAutoresizingFlexibleBottomMargin) we got success removing the Top one.

EDIT I don't know if this is a definitive solution, but I noticed everywhere the issue happened I had a fixed origin (x or y) on the frame. For example:

view.frame=(view1.frame.origin.x, 150, width, height);

Changing the fixed value in a relative value (for example respect to another view1) solved the issue with masks:

view.frame=(view1.frame.origin.x, view1.frame.origin.y+view1.frame.size.height+20, width, height);

like image 21
Donnit Avatar answered Oct 04 '22 20:10

Donnit