简体   繁体   English

有没有办法在Plus上模拟较小的iPhone?

[英]Is there a way to simulate a smaller iPhone on my Plus?

I have an iPhone Plus which I'm using for development. 我有用于开发的iPhone Plus。 I'm concerned that my app would be cramped or otherwise not have a good UI on 4-inch phones like the SE. 我担心自己的应用会局促,或者在SE等4英寸手机上没有良好的UI。 Is there a way to simulate a 4-inch phone on the Plus? 有没有办法在Plus上模拟4英寸手机? I imagine it would leave blank space at the top and sides of the screen. 我想这会在屏幕的顶部和侧面留下空白。

The simulator doesn't work, since the scale is wrong. 模拟器不起作用,因为比例错误。 Everything appears bigger. 一切看起来都更大。 It's also hard to test touch gestures on the simulator to see if they feel natural. 很难在模拟器上测试触摸手势是否自然。 Finally, it's a camera app, so it doesn't run on the simulator. 最后,它是一个相机应用程序,因此它不能在模拟器上运行。

I'm fine with a third-party app or library to do this. 我可以使用第三方应用程序或库来做到这一点。

You can easily simulate this using a container view controller: 您可以使用容器视图控制器轻松地对此进行模拟:

class FourInchViewController: UIViewController {

  init(child: UIViewController) {
    self.child = child
    super.init(nibName: nil, bundle: nil)

    addChildViewController(child)
  }




  // Internals:

  private let child: UIViewController

  override func loadView() {
    let black = UIView()
    black.backgroundColor = .black
    view = black

    view.addSubview(child.view)
  }

  override func viewWillLayoutSubviews() {
    let size = view.bounds.size
    let w = CGFloat(320), h = CGFloat(568)
    child.view.frame = CGRect(
        x:(size.width - w)/2,
        y:size.height - h,
        width: w,
        height: h)
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

Then, in your app delegate, set this as your root view controller. 然后,在您的应用程序委托中,将其设置为您的根视图控制器。

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

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