【问题标题】:View not covering full screen (programmatic storyboard Swift)查看不覆盖全屏(编程故事板 Swift)
【发布时间】: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


【解决方案1】:

确保您有一个 LaunchScreen 故事板。

【讨论】:

  • 这是我的问题!谢谢!
【解决方案2】:

似乎不可能以编程方式执行 LaunchScreen,因为屏幕将在应用程序启动之前由操作系统加载,请参阅 here

【讨论】:

    猜你喜欢
    • 2020-07-27
    • 1970-01-01
    • 2016-01-09
    • 2019-06-26
    • 2012-01-20
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多