Wednesday, February 8, 2023
HomeiOS Developmentios - Bounce animation is working solely after second faucet

ios – Bounce animation is working solely after second faucet [SwiftUI]


I’m triggering animation after unhiding the view sadly animation just isn’t working until I faucet twice

   struct ContentView: View {

    @State var animate = false
    @State var isViewHidden: Bool = true
    
    var physique: some View {
        VStack {
            ZStack {
                    Circle()
                        .fill(.blue).opacity(0.25).body(width: 40, peak: 40).offset(y: self.animate ? 0 : 60)
                        .hides(isViewHidden)
                }
                .animation((Animation.linear(period: 1.5).repeatForever(autoreverses: true))
                           , worth: self.animate ? 0 : 60)
            Spacer()
            Button("Faucet right here") {
                self.isViewHidden = false
                self.animate.toggle()
            }
        }
        .padding()
    }
}

extension View {
    @ViewBuilder
    func hides(_ isHidden: Bool) -> some View {
        if isHidden {
            hidden()
        } else {
            self
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments