Autoresizing not working in iOS11 / XCode 9

2019-03-16 04:01发布

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.

2条回答
神经病院院长
2楼-- · 2019-03-16 04:34

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-03-16 04:38

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);

查看更多
登录 后发表回答