我在 SwiftUI 中遇到了一种奇怪的行为,我似乎无法解决它。
鉴于以下简单的示例应用程序,我遇到了这种行为:工具栏项目在初始运行时正确呈现,但导航离开并返回它会被剪切。
重新创建此示例代码:
内容视图.swift
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: View2()) {
Text("Hello, world!")
.padding()
.navigationTitle("View 1")
.toolbar {
Circle()
.fill(Color.red)
.frame(width: 150, height: 150, alignment: .center)
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
View2.swift
import SwiftUI
struct View2: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
struct View2_Previews: PreviewProvider {
static var previews: some View …Run Code Online (Sandbox Code Playgroud) ios swift swiftui swiftui-navigationlink swiftui-navigationview