1

I'm trying to make this Profile Button to work inside a ScrollView, that when tapped, a modal view should come up. But for some reason, when I add some offset to the Button, to make it inline with the Navigation Title, the Button stops working.

Does anyone know a fix for this?

Here's my code:

import SwiftUI

struct TestView: View {
   @State var showMenu = false
   var body: some View {
       NavigationView {
           
           ScrollView {
               
                   VStack {
                       
                       HStack {
                           
                           Spacer()
                           
                           Image(systemName: "person.crop.circle")
                               .font(.system(size: 36))
                               .foregroundColor(.blue)
                               .frame(width: 44, height: 44)
                               .onTapGesture {
                                   showMenu.toggle()
                               }
                               .offset(y: -64)
                           
                       }
                      
                       Spacer()
                           
                   }
                   .padding()
                   .sheet(isPresented: $showMenu) {
                       MenuView()
        
               }
          }
           .navigationTitle("Browse")
       }
   }
}

struct TestView_Previews: PreviewProvider {
   static var previews: some View {
       TestView()
   }
}


SwiftUI View

joaquin737
  • 41
  • 3
  • 1
    The navigation bar is covering the button. You might want to take a look at [this](https://stackoverflow.com/a/64244584/14351818) – aheze Nov 17 '20 at 05:01

0 Answers0