覆盖模拟器设备上的屏幕大小

时间:2018-06-20 14:36:00

标签: ios autolayout uiscreen

我想知道是否可以覆盖设置中的屏幕尺寸并重新加载您的应用。

我想这样做,以便例如在打开iPhone X的情况下,能够在我的应用程序上打开调试菜单,并且默认设置覆盖屏幕尺寸,重新加载应用程序并使其可作为iPhone 6的大小。

我想这样做,以便可以测试所有不同的屏幕尺寸,而无需在所有不同的模拟器上编译和运行应用程序。

谢谢!

2 个答案:

答案 0 :(得分:0)

这是不可能的。您需要通过在要测试的每个不同大小的模拟器上运行来进行构建和测试。

答案 1 :(得分:0)

您要询问的内容无法通过这种方式完成,只有您可以创建具有不同框架的新窗口,然后才能在其他设备的屏幕上使用。但是您可以根据计算每个设备的纵横比并根据其更改视图的高度来更改当前的视图控制器视图框架,或者也可以使用局部尺寸来制作矩形。

让扩展程序在任何地方使用它:

例如:

extension UIViewController {
   /* With exact value */
   func convertTo3_5inch() {
       // 320 × 480
       if UIScreen.main.bounds.height >= 480 {
           self.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
           self.view.layoutIfNeeded()
       }
   }
   /* With Ratio */
   func convertTo16_9ratio() {
       // 320 * 568
       if UIScreen.main.bounds.height >= 568 {
           self.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.width*16)/9)
           self.view.layoutIfNeeded()
       } else {
           print("Screen size smaller than the size your are converting to")
       }

   }
   /* call this func in button */
   func changeAction() {
       let action = UIAlertController(title: "Options", message: nil, preferredStyle: .actionSheet)
       action.addAction(UIAlertAction(title: "3.5inch", style: .default, handler: { (action) in
           self.convertTo3_5inch()
    }))

       action.addAction(UIAlertAction(title: "5to8plus", style: .default, handler: { (action) in
           self.convertTo16_9ratio()
    }))

       self.present(action, animated: true, completion: .none)
   }
}

根据需要进行自定义,

相关问题