Hi ostoura,
have you considered to use the AnimationPlaybackController returned by the playAnimation method?
Store the playbackController when initially play the animation
@State private var playbackController: AnimationPlaybackController?
Modify your playThis() to:
func playThis() {
guard let animationResource = manPlayer.availableAnimations.first else { return }
playbackController = manPlayer.playAnimation(animationResource.repeat(duration: .infinity), transitionDuration: 0.25, startsPaused: false) //infinity looping, smooth transition, animation starts immediately
playbackController?.speed = speed
}
Adjust speed functions
func increaseSpeed() {
speed += 0.1
playbackController?.speed = speed
}
func decreaseSpeed() {
speed = max(0.1, speed - 0.1) // prevent negative or zero speed
playbackController?.speed = speed
}
Now you should be able to adjust the animation speed while it is running
I hope this helps
Flip
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: