IOS AutoLayout Change position on Rotation

后端 未结 2 466
自闭症患者
自闭症患者 2021-01-16 10:47

I wanted to sent one container below the other on portrait and side by side on landscape. Is it possible with just auto layout? I know i can do it programmatically, just won

2条回答
  •  没有蜡笔的小新
    2021-01-16 11:17

    Yep, I think there is going to be a little code though. So the I believe the 2 constraints involved here are horizontal spacing and vertical spacing (Editor -> Pin -> Horizontal/Vertical).

    Arrange A and B in the portrait layout, select both of the elements, and add both of those constraints. Create IBOutlets to both of these constraints in the header file (just like you would a label, button, etc)

    You can then change the values of these constraints in the "didRotateFromInterfaceOrientation" delegate method (constraint_variable_name.constant = 0;). Let me know if any of this is unclear or you need me to elaborate on any part of it.

提交回复
热议问题