我想知道是否可以在设置中覆盖屏幕大小并重新加载您的应用程序。
我想这样做,例如,如果我打开了 iPhone X,我可以在我的应用程序上打开一个调试菜单并默认覆盖屏幕大小,重新加载应用程序,并让它可以作为一个大小进行测试iPhone 6。
我想这样做,以便我可以测试所有不同的屏幕尺寸,而无需在所有不同的模拟器上编译和运行应用程序。
提前致谢!
我想知道是否可以在设置中覆盖屏幕大小并重新加载您的应用程序。
我想这样做,例如,如果我打开了 iPhone X,我可以在我的应用程序上打开一个调试菜单并默认覆盖屏幕大小,重新加载应用程序,并让它可以作为一个大小进行测试iPhone 6。
我想这样做,以便我可以测试所有不同的屏幕尺寸,而无需在所有不同的模拟器上编译和运行应用程序。
提前致谢!
您所要求的不能那样做,只有您可以创建具有不同框架的新窗口,但可以在另一个设备的屏幕上使用。但是您可以根据计算每个设备的纵横比并据此更改视图的高度来更改当前视图控制器的视图框架,或者您也可以使用本地尺寸制作矩形。
让扩展在任何地方使用它:
例如:
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)
}
}
根据您的需要定制,
这是不可能的。您需要通过在您希望测试的每个不同大小的模拟器上运行来构建和测试。