【发布时间】:2020-03-12 12:51:24
【问题描述】:
现在在 SceneDelegate 中配置了 Xcode 11 的初始窗口,这里是我的代码和图片上的结果:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
print("Scene willConnectTo.")
guard let windowScene = (scene as? UIWindowScene) else { return }
// window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window = self.window ?? UIWindow()
let mainView = ViewController()
mainView.title = "TEST"
let navigationController = UINavigationController()
navigationController.viewControllers = [mainView]
window?.backgroundColor = .red
window?.windowScene = windowScene
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
谁能建议如何让视图覆盖所有屏幕?
【问题讨论】:
-
这段代码在我的模拟器中运行良好。 iPhone 8/11 Pro 上没有黑线。你对 ViewController 中的视图有什么限制?你能告诉我用 UIViewController() 替换它是否对你有任何改变吗?
-
在 VC 中没有任何约束,如果用 UIViewController 替换它是程序化的,但我需要自定义
-
我明白了。我尝试使用自定义 VC 并且它有效。你能展示你的VC代码吗?特别是您在 VC 的 self.view 中添加的内容的代码。
-
VC 是空的,只是空白模板。
-
你能给它添加一个视图吗?让它伸展到所有4个方面?就像 let contentView = UIView() view.addSubview(contentView) contentView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ contentView.leftAnchor.constraint(equalTo: view.leftAnchor), contentView.topAnchor.constraint(equalTo: view.topAnchor), contentView .bottomAnchor.constraint(equalTo: view.bottomAnchor), contentView.rightAnchor.constraint(equalTo: view.rightAnchor) ])
标签: ios xcode storyboard interface-builder