问题:点击这个黑色区域不会 print,黑色区域看上去刚好是 Spacer() 占据的区域
解决办法:不使用 onTapGesture,用 Button 包裹一下
Code:
import SwiftUI
struct TestTap: View {
var body: some View {
NavigationStack {
List {
Section {
Button {
print("Tap !!!", Date.now)
} label: {
HStack(spacing: 0) {
Image(systemName: "swift")
.resizable()
.scaledToFit()
.frame(width: 66)
.foregroundColor(.yellow)
.border(.yellow)
Text("Swift")
.foregroundColor(.green)
.border(.green)
Spacer()
Image(systemName: "checkmark.circle.fill")
.font(.title2)
.foregroundColor(.blue)
.border(.blue)
}
.border(.red)
}
}
}
}
}
}
struct TestTap_Previews: PreviewProvider {
static var previews: some View {
TestTap()
}
}