【问题标题】:Why does Xcode Playground execute liveView through iPad-like Simulator?为什么 Xcode Playground 会通过类似 iPad 的 Simulator 来执行 liveView?
【发布时间】:2017-07-16 02:39:15
【问题描述】:

我正在使用 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

【问题讨论】:

标签: ios swift xcode ipad swift-playground


【解决方案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 中更改视图控制器大小的方式

【讨论】:

    【解决方案2】:

    可能与“Swift Playgrounds”应用有关?

    该应用仅适用于 iPad(您甚至无法在 iPhone 上的 App Store 中找到它)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-20
      • 2014-09-20
      • 1970-01-01
      • 2020-10-28
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多