UISpringTimingParameters doesn't respect direction of initialVelocity for translation affine transform animations

Originator:david.ronnqvist
Number:rdar://32846697 Date Originated:June 19 2017
Status:Open Resolved:
Product:iOS + SDK Product Version:
Classification: Reproducible:
 
Area:
UIKit

Summary:
When using a `UIPanGestureRecognizer` to drag a view that is positioned using Auto Layout, it is best to modify the views `transform` to offset it based on `panGesture.translation(in: view)`. When the pan gesture is ended, the view can snap back to its original position by animating the transform to `.identity`.

If the view is stationary when the gesture is ended this looks really nice with a spring animation that snaps the view into place. But if the user is moving their finger as they let go, it would look more physical/natural if the view was thrown with the current velocity of the pan. Conveniently `panGesture.velocity(in: view)` gives the velocity of the pan and `UIViewPropertyAnimator` with `UISpringTimingParameters(dampingRatio:initialVelocity:)` can perform a spring animation with a initial velocity vector. 

However, when animating the transform - even when it's only a translation - the direction of `initialVelocity` is ignored and instead the direction is along the straight line from the current translated location to the new (untranslated) location.

It is possible to workaround this and get the expected animation by both offsetting the view's `center` by the translation and setting the translation to `.identity` without an animation and then animating the view's `center` to it's expected end value. Since this is animating the position of the layer it respects the direction of the velocity, making the view enter the animation with the same velocity vector as it had when the pan gesture ended.

This API would be more convenient if the translation of a `CGAffineTransform` would animate/interpolate it's `tx` and `ty` components with respect to the initial velocity vector.

Steps to Reproduce:
Perform a vertical or diagonal translation animation with a horizontal initial velocity vector using `UIViewPropertyAnimator` and `UISpringTimingParameters`.

Expected Results:
The direction of the initial velocity is horizontal.

Observed Results:
The direction of the initial velocity is along the straight line from the start location to the end location.

Version:
iOS 11 ß1

Notes:
The same steps works as expected when animating the `center` of the view instead of the `transform`.

Configuration:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!