小编Jam*_*mey的帖子

为什么 SwiftUI View 背景会延伸到安全区域?

这是导航到第二个视图的视图:

\n
struct ContentView: View {\n    var body: some View {\n        NavigationView {\n            NavigationLink {\n                SecondView()\n            } label: {\n                Text("Go to 2nd view")\n            }\n        }\n        \n    }\n}\n\n\n struct SecondView: View {\n     var body: some View {\n         ZStack {\n             Color.red\n             VStack {\n                 Text("This is a test")\n                     .background(.green)\n                 //Spacer() // <--If you add this, it pushes the Text to the top, but its background no longer respects the safe area--why is this?\n             }\n         }\n     }\n }\n
Run Code Online (Sandbox Code Playgroud)\n

在第二个屏幕上,视图的绿色背景Text仅延伸到其边框,这是有道理的,因为文本是拉入视图:

\n

在此输入图像描述

\n …

xcode swift swiftui

9
推荐指数
1
解决办法
3306
查看次数

标签 统计

swift ×1

swiftui ×1

xcode ×1