Saturday, August 19, 2023
HomeiOS Developmentios - Methods to make the animation go slower SwiftUI

ios – Methods to make the animation go slower SwiftUI


I’ve carried out a picture with a rotating animation together with three buttons to regulate the rotation velocity. The velocity is managed by modifying the animation length. Nevertheless, I am dealing with a problem the place making an attempt to decelerate the animation leads to it repeatedly dashing up as a substitute.

Right here is my code snippet:

import SwiftUI

struct ContentView: View {
    
    @State personal var rotationAngle: Angle = .levels(0)
    @State var imageSpeed  : Double = 1.5
    var physique: some View {
        VStack {
            Picture("j")
                .resizable()
                .body(width: 100, peak: 100)
                .rotationEffect(rotationAngle, anchor: .heart)
                .onChange(of: imageSpeed){ _ in
                    rotationAngle = .levels(0)
                    let animation = Animation.linear(length: imageSpeed).repeatForever(autoreverses: false)
                    withAnimation(animation) {
                        
                        rotationAngle = .levels(360)
                        
                    }
                    print(imageSpeed)
                }
            HStack {
                Button(motion: {
                    
                    imageSpeed = 4
                }) {
                    Textual content("Sluggish")
                    
                }
                
                Button(motion: {
                    imageSpeed = 1
                }) {
                    Textual content("Quick")
                }
                
                Button(motion: {
                    imageSpeed = 0.0
                }) {
                    Textual content("Cease")
                }
            }
            .padding(.high, 20)
        }
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

I gave the code above a strive, but it surely did not produce the anticipated end result. I’d actually recognize any assist with this challenge.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments