问题
I am creating a UIStackView with two buttons + & -. In the landscape mode the stackview it looks like this with vertical axis.
And in portrait mode it has horizontal axis like this:
Problem: Each button +/- is 50 points high. In landscape, I set w=50 & h=140 for the stack view whereas for portrait I set w=200 & h=50. I set the spacing property of UIStackView of 20 points in landscape and 100 points in portrait. I use 'Vary for Traits' to define different constraints for the two modes as well as customize properties of UIStackView such as Axis, Spacing using 'Add Variation' in storyboard. But on autorotation I get lot of auto-layout errors that I simply can not fix, such as this one:
(
"<NSLayoutConstraint:0x60000009d240 UIButton:0x7fdcc6d152d0.height == 50 (active)>",
"<NSLayoutConstraint:0x60000009d7e0 UIStackView:0x7fdcc6d15110.height == 50 (active)>",
"<NSLayoutConstraint:0x60000009d830 V:|-(0)-[UIButton:0x7fdcc6d152d0] (active, names: '|':UIStackView:0x7fdcc6d15110 )>",
"<NSLayoutConstraint:0x60000009d8d0 V:[UIButton:0x7fdcca006970]-(0)-| (active, names: '|':UIStackView:0x7fdcc6d15110 )>",
"<NSLayoutConstraint:0x61000009f400 'UISV-spacing' V:[UIButton:0x7fdcc6d152d0]-(>=20)-[UIButton:0x7fdcca006970] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000009d240 UIButton:0x7fdcc6d152d0.height == 50 (active)>
What do I do I wonder? Seems like I can not change default constraints that come with UIStackView in storyboard.
来源:https://stackoverflow.com/questions/46214272/uistackview-autolayout-constraints