Swift Playground UIView 的大小不正确

Swift Playground UIView has incorrect size

我一直在 XCode 中使用 Swift 游乐场,并将大小设置为 4:3 比率(如 iPad),大小为 1024 像素768 像素。但是,当我实际上 运行 iPad 和 Mac 上的代码时,大小显示不正确,纵横比也不正确。奇怪的是,当大小设置为 600 像素 x 600 像素时,它工作得很好。先感谢您!下面的 UI 视图应该看起来像 iPad 而不是 iPhone。

不正确的suze/aspect比率

正如@Sweeper 所说,我也认为你不能设置根视图,但是如果你只是想看看 UI 在 playground 中的样子,然后才能将其设置为你的实际视图在视图控制器中。 (尽管您仍然需要检查设备是 iPad 还是 iPhone,然后相应地设置宽度和高度)。

但这里是给你玩的,而不是单视图应用程序,select playground 为空白,然后在那里设置宽度和高度。或者让你的当前代码跟随,希望它有帮助,谢谢:

import PlaygroundSupport

let view = UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 1024, height: 768)))
view.backgroundColor = .white
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = view