简体   繁体   English

在iOS中使用自动布局更改设备旋转的视图方向

[英]Change orientation of view on device rotation using Autolayout in iOS

I need to change position of squared view on device rotation using autolayout in storyboard. 我需要使用情节提要中的自动布局在设备旋转时更改平方视图的位置。 Please refer below picture for better understanding of problem. 请参考下图以更好地了解问题。 在此处输入图片说明

do you have idea about trait variations you can designed a storyboard file in two different way like one for portrait and one for landscape i have created a demo what you explained in your question via images. 您有关于特质变化的想法吗,可以用两种不同的方式设计一个故事板文件,例如一种用于肖像,一种用于风景,我创建了一个演示,您通过图像在问题中进行了解释。

PLEASE CHECK THIS DEMO APPLICATION 请检查此演示应用程序

In storyboard set the portrait layout in compact width regular height(wC hR) and landscape layout in regular width compact height(wR hC). 在情节提要中,将肖像版式设置为紧凑宽度常规高度(wC hR),将风景版式设置为常规宽度紧凑高度(wR hC)。

This will handle the positioning of the objects in different orientation. 这将以不同的方向处理对象的定位。

Edited: When you add a constraint to wChR it gets added to all layouts. 编辑:向wChR添加约束时,它会添加到所有布局中。 So double click the constraint and install it only to wChR. 因此,双击约束并将其仅安装到wChR。 Then go to wRhC add needed constraints and install it only to wRhC. 然后转到wRhC,添加所需的约束并将其仅安装到wRhC。 In case of common constraint like height, width you can select the layout by double click of constraint and set different values if needed. 对于高度,宽度等常见约束,您可以通过双击约束来选择布局,并根据需要设置不同的值。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM