向 SwiftUI 按钮添加填充时没有响应

时间:2021-06-12 11:20:33

标签: ios swift xcode swiftui

    "scripts": {
        ...
        "dev": "babel src --watch --out-dir dist --extensions .ts --source-maps inline & sleep 5 && nodemon"
        ...

当我尝试在我的 HStack 周围添加 padding(.top, 50) 以将其定位得低一点时,我的按钮在图像区域上停止响应并且只能在上面的填充区域上单击。我不明白为什么会这样,我如何才能在不干扰按钮点击区域的情况下将我的 HStack 放低。

1 个答案:

答案 0 :(得分:0)

要清楚这是我用于测试的代码:

    @main
    struct TestApp: App {
        var body: some Scene {
            WindowGroup {
                ContentView()
            }
        }
    }
    
struct ContactView: View {
    
    @Binding var isContactViewActive: Bool
    @State var searchBar = ""
    
    var backgroundColor = Color(red: 14/255, green: 18/255, blue: 23/255, opacity: 1.0)
    
    var body: some View {
        NavigationView {
            ZStack {
                backgroundColor
                VStack {
                    HStack {
                        Button(action: {print("magnifyingglass")}, label: {
                            Image(systemName: "magnifyingglass").font(.title)
                        })
                        Spacer()
                        Text("FireChat")
                            .font(.title)
                            .fontWeight(.light)
                            .foregroundColor(Color.white)
                        Spacer()
                        Button(action: {print("power")}, label: {
                            Image(systemName: "power").font(.title)
                        })
                    }.padding(.top, 50)
                }
            }.edgesIgnoringSafeArea(.all)
        }
    }
}

struct ContentView: View {
    @State var isContactViewActive = false
    var body: some View {
        ContactView(isContactViewActive: $isContactViewActive)
    }
}
相关问题