【发布时间】:2019-03-19 03:52:28
【问题描述】:
我正在尝试使用以下代码在 iPad Playgrounds 中展示这个简单的 ViewController:
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
}
func setupViews() {
let view1 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width/2, height: 100))
view1.backgroundColor = .red
view.addSubview(view1)
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
您可以看到,即使它为 View1 的框架显示 view.frame.width/2,但视图仍然是这样的:
怎么了?谢谢。
【问题讨论】:
-
如果你将半屏预览的边缘一直拖到左边——这样你就可以得到全屏预览——红色视图是否仍然覆盖了整个宽度?我怀疑问题在于
MyViewController实时视图太大而无法容纳预览,因此似乎裁剪为预览大小。 -
有点奇怪,如果我把它一直拖出来,如果我把它一直拖出来,它会覆盖大约 60% 的宽度。
标签: swift xcode ipad swift-playground ipad-playgrounds