如何在现场游乐场调整视图大小?? Xcode

how to resize a view in live playgrounds ?? Xcode

我计划为即将到来的 wwdc 奖学金创建一个现场游乐场,但我没有创建现场游乐场的经验,因为到目前为止我一直在使用单视图应用程序

我实际上不知道我的操场上的视图应该是多大,我无法调整它的大小谁能告诉我该怎么做,我已经尝试了下面的代码,但它给了我错误和不起作用请帮助我,感谢与 wwdc 项目相关的任何建议谢谢

 let main = viewController()
main.view.frame.size = CGSize(width: 300, height: 600)

此代码给出错误:= 表达式解析失败,未知错误

请告诉我如何调整视图大小以及我应该怎么做??

您应该更改整个 framebounds 属性以调整视图大小:

import UIKit
import PlaygroundSupport

class ViewController : UIViewController {
    ...
}

let viewController = ViewController()
viewController.view.frame = CGRect(x: 0, y: 0, width: 300, height: 600)
PlaygroundPage.current.liveView = viewController
PlaygroundPage.current.needsIndefiniteExecution = true

当您使用 navbar 时,重要的是调整 NavigationController 的大小而不是 ViewController。

像这样:

let vc = MyViewController()
let navBar = UINavigationController(rootViewController: vc)
navBar.view.frame = CGRect(x: 0, y: 0, width: 320, height: 568)
PlaygroundPage.current.liveView = navBar