【发布时间】:2020-07-17 08:21:29
【问题描述】:
我有一个包含 TabView 的 ContentView.swift。
View1 中有一个带有一些子视图的 NavigationView。 View2 只是一个单一的视图。
当第一个 tabItem 被按下时,我想执行一些操作(总是返回 View1,即使在 View1 的 childView 中)。 即使它已经是活动的 tabItem。
我尝试了如下所示的 onTapGesture,但它似乎没有做任何事情。在“.tag(0)”之前添加它也没有改变任何东西:
TabView {
View1()
.onTapGesture {
print("Test")
}
.tabItem {
Image(systemName: "doc.plaintext")
.font(.system(size: 25))
Text("View1")
}.tag(0)
View2()
.tabItem {
Image(systemName: "person.crop.circle")
.font(.system(size: 25))
Text("View2")
}.tag(1)
【问题讨论】: