使用contentShape()使整个VStack区域tappable可点击


1年前 728次点击 来自 移动端

标签: 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响应点击事件")
        }
    }
}

Made with in Shangrao,China By Devler.

Copyright © Devler 2012 - 2022

赣ICP备19009883号-1

Top ↑