Skip to content

What is the best way to set the duration of an animation in SwiftUI? #2302

Answered by calda
imthath-m asked this question in Q&A
Discussion options

You must be logged in to vote

Another option is to use a .configure { ... } with something like this:

.configure { animationView in
  guard let animation = animationView.animation else { return }
  let expectedSpeed = animation.speedToPlay(forDuration: 10)

  if animationView.animationSpeed != expectedSpeed {
    animationView.animationSpeed = expectedSpeed
  }
}

This could be wrapped up in a custom view modifier like .duration(10) and seems appealing since then you don't have to pass the animation into the view modifier.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@calda
Comment options

Answer selected by imthath-m
@imthath-m
Comment options

@calda
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants