ios快速改变方向将改变UIView Design

时间:2017-08-10 11:24:01

标签: ios swift swift3 uiview

在我的项目中,更改方向将更改相同ViewController的UIView设计 画像:
enter image description here

风景
enter image description here

在同一个ViewController中更改不同方向样式的设计。

2 个答案:

答案 0 :(得分:4)

您正在寻找的答案是UIStackView

Here is Apple Doc if you really want to go into it

实现UIStackView很容易

1)选择要生效的所有视图 2)选择嵌入在Stackview中,如下图所示

Using UIStackview

3)设置您的UIStackView

enter image description here

这里是你的UIStackview属性的样子。

enter image description here

UIStackView管理您的屏幕旋转,您可以根据需要设置两种不同的布局。

答案 1 :(得分:2)

您应该查看Size Classes概念。 例如,在youtube上观看此视频,了解其工作原理。 https://youtu.be/7iT9fueKCJM

您也可以在轮换后以编程方式设置约束:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

        if (UIDevice.currentDevice().orientation.isLandscape) {
            // ------ Landscape -----
            // Setup constraints

        } else {
            // ----- Portrait -----
            // Setup constraints
        }
    }