IOS迅速变化的方向会改变的UIView设计

问题描述:

在我的项目
变化方向将改变UIView的设计相同ViewController
肖像:
enter image description hereIOS迅速变化的方向会改变的UIView设计

景观
enter image description here

在相同的ViewController更改设计不同的方向风格。

+0

这是什么问题?如何做到这一点?所以广场不只是改变方向而是相互定位?在IB还是代码? – agibson007

你正在寻找的答案是UIStackView

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

实施UIStackView容易

1)选择你想要生效的所有视图像下面

Using UIStackview

3)设置你的UIStackView显示2)选择嵌入在Stackview图像

enter image description here

这里您UIStackview财产将如何样子。

enter image description here

UIStackView管理您的屏幕旋转,你可以有两个不同的布局,你的愿望。

你应该看看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 
     } 
    }