Apple docs say this about translatesAutoresizingMaskIntoConstraints
If this property’s value is true, the system creates a set of constraints that duplicate the behavior specified by the view’s autoresizing mask. This also lets you modify the view’s size and location using the view’s frame, bounds, or center properties, allowing you to create a static, frame-based layout within Auto Layout.
Note that the autoresizing mask constraints fully specify the view’s size and position; therefore, you cannot add additional constraints to modify this size or position without introducing conflicts. If you want to use Auto Layout to dynamically calculate the size and position of your view, you must set this property to false, and then provide a non ambiguous, nonconflicting set of constraints for the view.
Focus on the highlighted part if I add a view using auto layout constraints setting translatesAutoresizingMaskIntoConstraints to false and then I change its frame or center value, the changes happen, but according to the doc above they shouldn't as translatesAutoresizingMaskIntoConstraints is set to false. Does changing center or frame, make translatesAutoresizingMaskIntoConstraints true again and break the auto layout constraints?
CodePudding user response:
if I add a view using auto layout constraints setting translatesAutoresizingMaskIntoConstraints to false and then I change its frame or center value, the changes happen
If you change the frame or center in a layoutSubviews
override, that's fine; you are cooperating with the autolayout engine.
But if you do it elsewhere, you'll be sorry. Your change may appear to work for a while, but as soon as something triggers layout, the view will jump back to where autolayout puts it.