ios - 为什么Xcode Playground通过类似iPad的模拟器执行liveView?-LMLPHP

我正在使用Swift 3在Xcode 8.2.1 Playground中尝试一些代码。
自从PlaygroundPage.current.liveView执行类似于iPad的模拟器以来,我一直感到困惑。
我想通过较小设备的模拟器测试键盘输入。我可以更好地处理吗?

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setupTextView()
    }

    private func setupTextView() {
        let textView = UITextView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
        textView.backgroundColor = .gray
        textView.isSelectable = true
        textView.font = textView.font?.withSize(20)
        view.addSubview(textView)
    }

}

let viewController = ViewController()
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 640, height: 600))
window.rootViewController = viewController
window.makeKeyAndVisible()

import PlaygroundSupport

PlaygroundPage.current.liveView = window
PlaygroundPage.current.needsIndefiniteExecution = true

最佳答案

代替

let viewController = ViewController()
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 640, height: 600))
window.rootViewController = viewController
window.makeKeyAndVisible()

import PlaygroundSupport

PlaygroundPage.current.liveView = window
PlaygroundPage.current.needsIndefiniteExecution = true

试试这个
let viewController = ViewController()
viewController.preferredContentSize = CGSize(width: 640, height: 600)

import PlaygroundSupport

PlaygroundPage.current.liveView = viewController
PlaygroundPage.current.needsIndefiniteExecution = true

这就是我在Playgrounds中更改 View Controller 大小的方法

10-08 12:58