Home > Net >  How to fix button over the View SwiftUI
How to fix button over the View SwiftUI

Time:01-05

I have a little issue and I do not know how can i solve this. Basically, i have a SwiftUI View which contains more "little" views, when the button is pressed, is changhing to the next View, but my Button is always over my view. How can I put the button on the same level with the View ?

 var body: some View {
        ZStack {
          
            ZStack {
                switch onboardingState {
                    
                case 0 :
                    welcomeSection
                        .transition(transition)
                case 1 :
                    detailOrder
                        .transition(transition)
                case 2 :
                    detailOrder2
                        .transition(transition)
                default:
                    EmptyView()
                }
            }
            VStack {
                Spacer()
                bottomButton
            }
            
            .padding(30)
        }
       
    }

Picture

CodePudding user response:

Try this

    var body: some View {
           VStack {
             
               ZStack {
                   switch onboardingState {
                       
                   case 0 :
                       welcomeSection
                           .transition(transition)
                   case 1 :
                       detailOrder
                           .transition(transition)
                   case 2 :
                       detailOrder2
                           .transition(transition)
                   default:
                       EmptyView()
                   }
               }
             
                   Spacer()
                   bottomButton
               
               .padding(30)
           }
          
       }

CodePudding user response:

You are using Zstack which is used for putting views on top of each other. change outer ZStack to Vstack and your problem is solved.

  •  Tags:  
  • Related