我有NavigationView在ContentView
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
BarView()
AdsView()
SelectTypeVideo()
Spacer()
}
.ignoresSafeArea(.all)
}
}
}
我不能在像BarView()这样的子结构中使用它
我试图使用第一个
if isSearch {
SearchBar()
}
或
.onTapGesture {
isSearch.toggle()
}
按下
没有响应我想从BarView()移动到SearchBar()
struct BarView: View {
@State var isSearch = false
var body: some View {
if isSearch {
SearchBar()
}
HStack {
ZStack {
HStack {
Button(action: { isSearch.toggle() }) {
ZStack {
Rectangle()
.fill(Color.white)
.cornerRadius(10)
.shadow(color: .black.opacity(0.2), radius: 10)
.frame(maxWidth: 35, maxHeight: 35)
.padding(.top, 25)
Image(systemName: "gear")
.padding(.top, 25).padding()
.foregroundColor(Color.black)
}
}
}
}
Spacer()
Text("other")
.padding(.top, 30).padding()
.font(.title)
}.padding(.top, 10)
}
}
对不起,如果问题很简单,但我没有找到解决方案
删除
if isSearch {
SearchBar()
}
从<<p> strong> BarView 然后像这样放到ContentView中
if isSearch {
SearchBar()
} else {
BarView()
}