If IB has an auto-layout view configured, what happens if you try to change its frame programmatically?

The project I started to help with has not used Auto Layout before, and I am updating it to use the Auto Layout and size classes. There is a decent amount of code for manipulating frames throughout the application (for example, setting the frame directly, rather than changing the constants of the constraint), and I wonder how this affects the view configured using the automatic layout constraints.

I am working on getting rid of the variable frames of parts of the code and changing it to update the constraint constants where necessary, but since I am not yet familiar with how each piece of code works, be useful in order to better understand how the automatic layout and changes to the encoded frame can affect each other, so if the view is not displayed properly at runtime, I can better determine if it was something that I created or perhaps part of the old code somewhere what you need to find and update mb.

+6
source share
1 answer

It is very simple. You just need to understand what a machine is.

Here's how it works. Limitations are just a list of instructions; they themselves do nothing. There is a system message layoutSubviews , which is sent when you are not in control, so you have to imagine that it can be sent at any time. When layoutSubviews actually sent, constraints are constrained and respected (by doing exactly what you will do, i.e. the runtime sets the frame or bounds and center each view).

This way you can change the frame view, but keep in mind that if layoutSubviews sent and the constraints do not match the set frame , the view will return to where the constraints say, to express it.

+8
source

All Articles