UIStackView Autolayout constraints

淺唱寂寞╮ 提交于 2019-12-11 17:04:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!