【问题标题】:SwiftUI NavigationView does not fit the screen verticallySwiftUI NavigationView 垂直不适合屏幕
【发布时间】:2020-05-07 17:05:17
【问题描述】:

无法使 NavigationView 完全扩展 Y 方向。 尝试了 .edgesIgnoringSafeArea(.all) 和 .frame() 的所有选项。 Preview Provider 显示一切都很酷,但 Simulator 和真实设备显示相反。 (附图片)

代码:

import SwiftUI
struct ContentView: View {
        var body: some View {
        NavigationView{
            ZStack{
                Color.blue
                VStack{
                    Text("Hello, World!")
                        .foregroundColor(Color.blue)
                        .fontWeight(.bold)
                        .font(.system(size: 36))
                }
            }
            .navigationBarHidden(true)
            .navigationBarTitle("")
            .navigationBarBackButtonHidden(true)
            .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
            .edgesIgnoringSafeArea(.all)
        }
    }
}

【问题讨论】:

  • 适用于 Xcode 11.4 / iOS 13.4
  • 谢谢,但我真的不明白为什么这对你有用。我已经掌握了 Xcode 11.4.1 版和装有 iOS 13.4.1 的设备,更不用说大量的模拟器了

标签: swift


【解决方案1】:

好的,我看不出它应该工作的任何原因,但是...尝试更改修饰符的位置,如下所示

NavigationView{
    ZStack{
        Color.blue
        VStack{
            Text("Hello, World!")
                .foregroundColor(Color.blue)
                .fontWeight(.bold)
                .font(.system(size: 36))
        }
    }
    .navigationBarHidden(true)
    .navigationBarTitle("")
    .navigationBarBackButtonHidden(true)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)

【讨论】:

    【解决方案2】:

    我终于想通了。该问题与 NavigationView 或任何视图无关。原来是在项目中强制存在 xib 文件(例如启动屏幕)的问题。在这个问题中,我没有提到我已经删除了所有 .storyboard 文件。 Here's the link for more:

    我的问题一开始就是个问题,对不起。

    【讨论】:

      猜你喜欢
      • 2015-01-12
      • 2020-02-22
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2023-02-21
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多