Say I have a view whose width is 1/2 of the superview in portrait, and 1/3 of the superview in landscape, I thought I could set different multipliers for that constraint, but size class doesn't have this feature.
Then I found a solution in the following post, which says I have to disable and enable constraints for different size classes.
Changing the multiplier of a constraint based on size class
I don't know how to do it. I only find a way of clearing all the constraints. But I don't want to rebuild all the constraints again. I just want change for the one constraint. If I delete that constraint in my current size class, it is also deleted in other size classes. Is there any way I can disable that constraint just for one specific size class?
Answers
Use isActive property.
As documentation says
The active state of the constraint. You can activate or deactivate a
constraint by changing this property. Note that only active
constraints affect the calculated layout. If you try to activate a
constraint whose items have no common ancestor, an exception is
thrown. For newly created constraints, the active property is NO by
default. Activating or deactivating the constraint calls
addConstraint: and removeConstraint: on the view that is the closest
common ancestor of the items managed by this constraint. Use this
property instead of calling addConstraint: or removeConstraint:
directly
Answers
This is how you delete a particular constraint in a particular size class
1.) select the specific size class you need
2.) Click on the view or uielement whose constraints you want to remove/add.
3.) All the constraints of that view or uielement is shown in the right side Attribute Inspector.
4.) Select the particular constraint you want to remove , which sets a blue border on that constraint.
5.) Then press Backspace.
This will delete it for that particular size class only.
This constraint now appears in grey on for that
View Controller.
コメント