2

Tap gesture on green does not work. Does anyone have a solution for this?

ZStack {
    Color.green
        .onTapGesture {
            print("green")
        }
    ScrollView {
        VStack {
            Spacer(minLength: 500)
            Color.red
                .onTapGesture {
                    print("red")
                }
                .frame(height: 800)
        }
    }
}

1 Answer 1

2

The thing you want is impossible because ScrollView is over the green View, but there is way like this:

    struct ContentView: View {
    
    func greenFunction() { print("green") }
    
    var body: some View {

        ZStack {
            
            Color.green.onTapGesture { greenFunction() }

            ScrollView {

                VStack(spacing: 0) {
                    
                    Color.white.opacity(0.01).frame(height: 500).onTapGesture { greenFunction() }
                    
                    Color.red.frame(height: 800).onTapGesture { print("red") }
                    
                }
            }

        }
        
        
        
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.