我试图切换Bool变量,以便在单击作为按钮的图像时可以取消隐藏视图。我不确定问题是什么,因为据我所知,一切都是对的。再说一遍,我对斯威夫特还很陌生。这是我的代码:
struct ContentView: View {
@State private var hideNew: Bool = true
var body: some View {
ZStack {
VStack {
HeaderView() //Error shows here: 'Missing argument parameter 'hideNew' in call'
.padding(.bottom, -1.5)
ScrollView {
CountdownView()
}
Spacer()
}
.frame(width: 600, height: 500)
if hideNew == false {
NewDateView()
}
}
}
}
// The view for the header section
struct HeaderView: View {
var buttonSize: CGFloat = 25
@Binding var hideNew: Bool
var body: some View {
Spacer()
.frame(maxHeight: 10)
HStack {
Spacer()
Text("Date Countdown")
.font(.largeTitle)
.padding(.trailing, -buttonSize)
Spacer()
Image(systemName: "plus")
.padding(.trailing, 10)
.frame(width: buttonSize, height: buttonSize)
.onTapGesture {
hideNew.toggle() //This is what I assume the issue is, but I don't actually know what's wrong.
}
}
Spacer()
.frame(height: 10)
ExtendedDivider()
.frame(height: 1.5)
}
}
任何帮助都将不胜感激。
干杯