How to set velocity for transform in UIViewPropertyAnimator?

Updated
Dec 24, 2021 5:39 PM
Created
Dec 24, 2021 5:38 PM
Tags
Attributes

do {
  let animator = UIViewPropertyAnimator(
    duration: 6,
    timingParameters: UISpringTimingParameters.init(
      dampingRatio: 1,
      initialVelocity: .init(dx: -2, dy: 0)
    )
  )

  animator.addAnimations {
    view.transform.tx = -50
  }

  animator.startAnimation()
}

do {
  let animator = UIViewPropertyAnimator(
    duration: 6,
    timingParameters: UISpringTimingParameters.init(
      dampingRatio: 1,
      initialVelocity: .init(dx: 10, dy: 0)
    )
  )

  animator.addAnimations {
    view.transform.ty = -50
  }

  animator.startAnimation()
}

do {
  let animator = UIViewPropertyAnimator(
    duration: 6,
    timingParameters: UISpringTimingParameters.init(
      dampingRatio: 1,
      initialVelocity: .init(dx: 0, dy: 0)
    )
  )

  animator.addAnimations {
    view.transform.a = 0.8
    view.transform.d = 0.8
  }

  animator.startAnimation()
}