0

I have an iPhone Plus which I'm using for development. I'm concerned that my app would be cramped or otherwise not have a good UI on 4-inch phones like the SE. Is there a way to simulate a 4-inch phone on the Plus? 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.

4

1 回答 1

0

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.

于 2017-02-27T12:53:27.233 回答