我正在使用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
答案 0 :(得分:1)
代替
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中更改视图控制器大小的方式
答案 1 :(得分:0)
它可能与“ Swift Playgrounds”应用有关?
该应用程序仅适用于iPad(您甚至无法在iPhone的App Store中找到它)。