#StackBounty: #swift #animation #uipangesturerecognizer #bounce #uiviewpropertyanimator UIViewPropertyAnimator's bounce effect

Bounty: 100

Let’s say I have an animator that moves a view from (0, 0) to (-120, 0):

let frameAnimator = UIViewPropertyAnimator(duration: duration, dampingRatio: 0.8)

animator.addAnimations { 
    switch state:
    case .normal: view.frame.origin.x = 0
    case .swiped: view.frame.origin.x = -120
    }
}

I use it together with UIPanGestureRecognizer, so that I can resize the view continuously along with the finger movements.

The issue comes when I want to add some sort of bouncing effect at the start or at the end of the animation. NOT just the damping ratio, but the bounce effect. The easiest way to imagine this is Swipe-To-Delete feature of UITableViewCell, where you can drag “Delete” button beyond its actual width, and then it bounces back.

Effectively what I want to achieve, is the way to set fractionComplete property outside of [0, 1] segment, so when the fraction is 1.2, the offset becomes 144 instead of its 120 maximum.

And right now the maximum value for fractionComplete is exactly 1.

Below are some examples to have this issue visualized:

What I currently have:
enter image description here

What I want to achieve:
enter image description here


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.