Monday, October 23, 2023
HomeiOS Developmentios - TabView web page change with button click on does not...

ios – TabView web page change with button click on does not work in swift ui


I attempted to implement web page flips in tab view by way of the choice choice in TabView. I initialized the state variable selectedPage and tagged the views. Then I attempted to vary the worth for selectedPage for button motion (get began, arrow left, arrow proper). Nevertheless, the button click on does not appear to work and change the pages. I’m not positive what went flawed right here – is there a step I’m lacking for switching tabs on button clicks?

import SwiftUI


struct ContentView: View {
    @State non-public var rotation = 0.0
    @State non-public var isSpinning = false
    @State var selectedPage = 1
    var darkGreen = Colour(pink: 0.00392156862745098, inexperienced: 0.09803921568627451, blue: 0.07058823529411765)
    
    non-public func spinWheel() {
           isSpinning = true
           rotation += Double.random(in: 720...1080)
           DispatchQueue.principal.asyncAfter(deadline: .now() + 2) {
               isSpinning = false
           }
       }
    func signIn() {
        print("hiya")
    }
    
    
    var physique: some View {
        TabView(choice: $selectedPage) {
            ZStack {
                darkGreen.edgesIgnoringSafeArea(.all)
                TabView {
                    ZStack{
                        VStack {
                            Textual content("abdsf").font(.system(measurement: 40, weight: .daring)).foregroundColor(.white).multilineTextAlignment(.heart).padding(.backside, 350)
                        }
                        VStack {
                            Textual content("information").font(.system(measurement: 16)).foregroundColor(.white).multilineTextAlignment(.heart).padding(.backside, 180)
                            
                        }
                        VStack {
                            Button(motion: {self.selectedPage = 2}) {
                                Textual content("Get Began")
                                    .padding(.horizontal, 80)
                                    .padding(.vertical, 15)
                                    .font(.system(measurement: 16, weight: .medium))
                                    .foregroundColor(darkGreen)
                                    .background(.white)
                                    .cornerRadius(25)
                            }
                        }.padding(.high, 450)
                    }.tag(1)
                    ZStack{
                        VStack {
                            Textual content("information").font(.system(measurement: 28)).foregroundColor(.white).multilineTextAlignment(.main).padding(.backside, 520).padding(.trailing, 210)
                        }
                        VStack {
                            Textual content("information").font(.system(measurement: 28, weight: .daring)).foregroundColor(.white).multilineTextAlignment(.main).padding(.backside, 450).padding(.trailing, 90)
                        }
                        VStack {
                            Textual content("information").font(.system(measurement: 28)).foregroundColor(.white).multilineTextAlignment(.main).padding(.backside, 380).padding(.trailing, 120)
                        }
                        VStack {
                            Picture("spinning-wheel")
                                .rotationEffect(.levels(rotation))
                        }.padding(.main, 370)
                        VStack {
                            Textual content("30").font(.system(measurement: 40, weight: .daring)).foregroundColor(.white).padding(.main, 145).padding(.backside, 12)
                        }
                        VStack{
                            Textual content("min").font(.system(measurement: 20, weight: .daring)).foregroundColor(.white).padding(.main, 230)
                        }
                        VStack {
                            Picture("axis")
                        }.padding(.main, 575)
                        
                        HStack{
                            Button(motion: {self.selectedPage = 1}) {
                                Picture(systemName: "arrow.left")
                                    .body(width:30, top: 30)
                                    .background(.white.opacity(0.5))
                                    .foregroundColor(.white)
                                    .clipShape(Circle())
                                    .padding(.trailing, 250)
                                    .padding(.high, 550)
                                
                            }

                            Button(motion: {self.selectedPage = 3}) {
                                Picture(systemName: "arrow.proper")
                                    .body(width:30, top: 30)
                                    .background(.white.opacity(0.5))
                                    .foregroundColor(.white)
                                    .clipShape(Circle()).padding(.high, 550)
                            }
                        }
                    }.tag(2)
                    ZStack{
                        VStack {
                            Textual content("information").font(.system(measurement: 28)).foregroundColor(.white).multilineTextAlignment(.main).padding(.high, 260).padding(.trailing, 235)
                        }
                        VStack {
                            Textual content("information").font(.system(measurement: 28, weight: .daring)).foregroundColor(.white).multilineTextAlignment(.main).padding(.high, 330).padding(.trailing, 90)
                        }
                        VStack {
                            Textual content("information").font(.system(measurement: 28)).foregroundColor(.white).multilineTextAlignment(.main).padding(.high, 400).padding(.trailing, 140)
                        }
                        HStack{
                            Button(motion: {self.selectedPage = 2}) {
                                Picture(systemName: "arrow.left")
                                    .body(width:30, top: 30)
                                    .background(.white.opacity(0.5))
                                    .foregroundColor(.white)
                                    .clipShape(Circle())
                                    .padding(.trailing, 250)
                                    .padding(.high, 550)
                            }

                            Button(motion: signIn) {
                                Picture(systemName: "arrow.proper")
                                    .body(width:30, top: 30)
                                    .background(.white.opacity(0.5))
                                    .foregroundColor(.white)
                                    .clipShape(Circle()).padding(.high, 550)
                            }
                        }
                    }.tag(3)
                    }
                }
            .tabViewStyle(.web page).gesture(DragGesture()
                .onChanged{ v in
                    spinWheel()
                }
            )
            }
        }
    }


#Preview {
    ContentView()
}




Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments