使用contentShape()使整个VStack区域tappable可点击
2年前 • 930次点击 • 来自 移动端
标签: SwiftUI
使用contentShape,整个VStack都可响应点击事件,若去除则只有Image和Text响应点击事件
struct contentShapeUIView: View {
var body: some View {
VStack {
Image("SSSS").resizable().frame(width: 50, height: 50)
Spacer().frame(height: 50)
Text("SSSS")
}
.contentShape(Rectangle())
.onTapGesture {
print("使用contentShape,整个VStack都可响应点击事件,若去除则只有Image和Text响应点击事件")
}
}
}