由于某些原因,当我添加填充修饰符时,onTapGesture修饰符无法工作。如果你看下面,你会看到3个地方,我试图添加填充修饰符。如果我注释掉/移除填充修饰符,onTapGesture修饰符可以正常工作,但是如果我取消注释任何一个填充修饰符,onTapGesture就会停止工作。我不知道这里发生了什么。
if noninitialRun == false {
ZStack(alignment: .topTrailing) {
Walkthrough()
//.padding(-16)
VStack {
Image(systemName: "xmark")
//.padding()
.onTapGesture {
print("tap")
noninitialRun = true
UserDefaults().setValue(true, forKey: "notFirstRun")
}
//.padding()
}
}
}发布于 2021-01-12 07:53:37
它与Xcode 12.3一起工作很好。我想是你的Xcode版本引起的。但是,您可以尝试:.contentShape(Rectangle())。
VStack {
Image(systemName: "xmark")
.padding()
.onTapGesture {
print("tap")
noninitialRun = true
UserDefaults().setValue(true, forKey: "notFirstRun")
}
.padding()
}.contentShape(Rectangle())https://stackoverflow.com/questions/65677808
复制相似问题