ios - SwiftUI TabView 问题
问题描述
我正在构建一个应用程序,而且我是 SwiftUI 的初学者,所以这就是我遇到的问题。我需要一个首先显示的登录页面,并且我已经为它创建了一个视图,您可以查看它。
struct LandingView: View {
var body: some View {
NavigationView{
VStack(alignment: .center){
Image("exxxlogo")
Spacer()
Text("Welcome")
.font(.system(size: 38))
.fontWeight(.bold)
.padding(.horizontal, 40)
.multilineTextAlignment(.center)
.foregroundColor(Color.white)
Text("Click below to continue to the app")
.font(.system(size: 16))
.padding(.horizontal, 20)
.multilineTextAlignment(.center)
.foregroundColor(Color.white)
.padding(.bottom, 35)
NavigationLink(destination: HomeView()){
Text("CONTINUE ")
.frame(width: 250, height: 50, alignment: .center)
.background(Color.red)
.foregroundColor(Color.white)
}
}
.background(
Image("backgroundlanding")
.frame(maxWidth: .infinity,maxHeight: .infinity)
.aspectRatio(contentMode: .fill)
.edgesIgnoringSafeArea(.top)
.edgesIgnoringSafeArea(.bottom)
)
}
而且我还为 tabview 创建了视图,以将它们重定向到 Home、Shop 等我已经完成了我的 Contentview
TabView {
HomeView()
.tabItem{
Image(systemName: "house")
Text("Home")
}
GamesView()
.tabItem{
Image(systemName: "gamecontroller")
Text("Games")
}
ShopView()
.tabItem{
Image(systemName: "bag")
Text("Shop")
}
MoreView()
.tabItem{
Image(systemName: "gear")
Text("More")
}.accentColor(.red)
并在 app.swift 主文件中将窗口组更改为landingview,使其首先弹出。但问题是当您单击landingview 中的按钮时,navigationlink 会将您重定向到主视图,但下面没有标签视图,只是空白
解决方案
您说您的第二个代码示例来自ContentView
. 如果你想展示TabView
你在其中拥有的东西ContentView
,那么你NavigationLink
应该指向ContentView
,而不是HomeView
。
NavigationLink(destination: ContentView()) {
Text("CONTINUE ")
.frame(width: 250, height: 50, alignment: .center)
.background(Color.red)
.foregroundColor(Color.white)
}
推荐阅读
- webpack - webpack 5 adds defer="defer" to script tags?
- sql-server - 即使在删除所有行、Trunc 数据表和 DBCC 重新种子后,使用重复主键自动增加身份错误
- import - 文件夹中文件的 Power Query 指定列选择
- reactjs - 测试 React 组件 props 处理程序
- angular - Angular - 如何在幻灯片工具的表单数组中设置值
- android - 在 ViewModel 中收集流。需要repeatOnLifeCycle 吗?
- html - 如何让 R Leaflet 状态的点击转到一个 url?
- postgresql - 是否有一种方法可以检测从 PostgreSQL 中精确定义的日期开始对数据库所做的所有更改?
- audio - 是否可以在不重新编码的情况下将立体声合并/缩混为单声道(m4a 或 opus)
- python - 如何在张量流中编写循环矩阵