similar to the demonstration here
我首先显示一个具有绿色背景的登录屏幕,然后用户点击登录,然后看到配置文件视图,该视图顶部具有绿色的不需要的东西。
我的目标是在整个屏幕上使用NavigationView。您可以清楚地看到视图是重叠的。
这是我提供视图的代码:
ViewRouter
class ViewRouter: ObservableObject {
let objectWillChange = PassthroughSubject<ViewRouter,Never>()
var currentPage: String = "login" {
didSet {
objectWillChange.send(self)
}
}
}
MotherView
struct MotherView: View {
@State var page = "login"
@ObservedObject var viewRouter: ViewRouter
@State var user = ""
@State var pass = ""
@State var login = false
@State var signup = false
var body: some View {
ZStack {
LinearGradient(gradient: .init(colors: [Color("1"),Color("2")]), startPoint: .leading, endPoint: .trailing).edgesIgnoringSafeArea(.all)
if viewRouter.currentPage == "login" {
Login(login: $login, signup: $signup, user: $user, pass: $pass, viewRouter: viewRouter)
} else if viewRouter.currentPage == "main" {
Main()
}
}.alert(isPresented: $login) {
Alert(title: Text(self.user), message: Text(self.pass), dismissButton: .none)
}.sheet(isPresented: $signup) {
signUp(signup: self.$signup)
}
}
}
主要
struct Main: View {
var body: some View {
TabView {
Profile()
.tabItem {
Image(systemName: "1.circle")
Text("Profile")
}.tag(0)
Text("Leaderboards")
.tabItem {
Image(systemName: "2.circle")
Text("Leaderboards")
}.tag(1)
Text("News")
.tabItem {
Image(systemName: "3.circle")
Text("News")
}.tag(2)
}
}
}
个人资料
struct Profile: View {
var body: some View {
NavigationView{
Text("Profile")
.navigationBarTitle("Profile", displayMode: .large)
}
}
}
我试图在 Profile 结构中为 NavigationView 设置偏移量和填充,但未得到任何结果。
答案 0 :(得分:1)
不幸的是,我无法测试我的答案。但是尝试一下:
struct Main: View {
var body: some View {
TabView {
...
} .edgesIgnoringSafeArea(.top)
}
}