3

as I know the translate auto resizing mask to constrains its allow to me set the view frame programmatically

I just set translatesAutoresizingMaskIntoConstraints to true, why constrains complain?

yara
  • 193
  • 1
  • 1
  • 6
  • Possible duplicate of [When should translatesAutoresizingMaskIntoConstraints be set to true?](https://stackoverflow.com/questions/47800210/when-should-translatesautoresizingmaskintoconstraints-be-set-to-true) – mfaani Nov 15 '18 at 12:09

3 Answers3

1

You need

translatesAutoresizingMaskIntoConstraints = false

when you create constraints in code this property should be false , as if true it will add other constraints , see Docs

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.

By default, the property is set to true for any view you programmatically create. If you add views in Interface Builder, the system automatically sets this property to false.

Community
  • 1
  • 1
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
1

Setting . translatesAutoresizingMaskIntoConstraints = true does NOT disable auto-layout.

It tells auto-layout to translate the frame setting and the .autoresizingMask property into constraints.

You still must provide valid frames to avoid conflicting / broken constraint warnings.

DonMag
  • 69,424
  • 5
  • 50
  • 86
1

translatesAutoresizingMaskIntoConstraints = true It tells auto-layout to translate the frame setting and the .autoresizingMask property into constraints. Why this warning poped to you? Because this line converts the frame layout to constrains, and in this case, the compiler removed already all your old constraints and started to convert the frame to constrain it to find only the height constrain it's still need to have two constraints for X, Y to dismiss the warning You still must provide valid frames to avoid conflicting/broken constraint warnings.

Abuzeid
  • 962
  • 10
  • 14