„View as“ Simulated Metrics influence maximum size of frame

I‘m using the current release version of Xcode 9 and I‘m encountaring a problem where changing the device to „view as“ in Interface Builder changes the frame size of some views when running the app in the simulator or on device. As far as I know, the simulated metrics of Interface Builder should never have any effect on constraints or sizes of views. I have one background view in particular that is set to top, bottom, leading, trailing = 0 to superview. The trailing side of the width of this view’s frame is always only as big as the selected device. So I basically need to set the simulated size width to the widest device that I support to make my view appear edge to edge on that device. I‘ve tried so many different constraint combinations and checkboxes in Xcode, but I still couldn‘t fix it. Does anyone have an idea where I could take a look to solve this problem? Thanks a lot in advance!

Accepted Reply

I was finally able to solve the bug!


To everyone who might encouter similar problems:

I was using a UIView subclass with IBInspectable properties. Some of those properties called "setNeedsLayout" in their didSet observer. Calling setNeedsLayout in different didSet observers seemed to somehow break or alter some of the layout constraints to use the simulated device size I set in Interface Builder.


Not calling setNeedsLayout and restructuring some of the ways my custom view gets drawn solved the problem completely and the constraints are now behaving exactly as they should. 🙂

Replies

I was finally able to solve the bug!


To everyone who might encouter similar problems:

I was using a UIView subclass with IBInspectable properties. Some of those properties called "setNeedsLayout" in their didSet observer. Calling setNeedsLayout in different didSet observers seemed to somehow break or alter some of the layout constraints to use the simulated device size I set in Interface Builder.


Not calling setNeedsLayout and restructuring some of the ways my custom view gets drawn solved the problem completely and the constraints are now behaving exactly as they should. 🙂