[英]onTapGesture not working with padding modifier in SwiftUI
For some reason, the onTapGesture modifier doesn't work when I add a padding modifier.出于某种原因,当我添加填充修饰符时,onTapGesture 修饰符不起作用。 If you look below, you'll see the 3 places where I've tried to add the padding modifier.如果你往下看,你会看到我尝试添加填充修饰符的 3 个地方。 The onTapGesture modifier works fine if I comment out/remove the padding modifier, but if i uncomment any of those paddings, the onTapGesture stops working.如果我注释掉/删除填充修饰符,onTapGesture 修饰符可以正常工作,但如果我取消注释任何这些填充,onTapGesture 将停止工作。 I don't know what's going on here.我不知道这里发生了什么。
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()
}
}
}
It works fine with Xcode 12.3.它适用于 Xcode 12.3。 I think your Xcode version caused it.我认为您的 Xcode 版本导致了它。 But nevertheless, you can try: .contentShape(Rectangle())
.但是,您可以尝试: .contentShape(Rectangle())
。
VStack {
Image(systemName: "xmark")
.padding()
.onTapGesture {
print("tap")
noninitialRun = true
UserDefaults().setValue(true, forKey: "notFirstRun")
}
.padding()
}.contentShape(Rectangle())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.