如何在实时游乐场中调整视图大小? Xcode

问题描述

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

我实际上不知道我的操场上的视图应该有多大,我无法调整它的大小,谁能告诉我怎么做,我已经尝试了下面的代码,但它给了我错误并且没有' t 工作请帮助我,任何与 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