Simulate UIScrollView Deceleration

后端 未结 2 790
后悔当初
后悔当初 2021-01-03 11:08

I have an UIPanGestureRecognize which I use to change the frame of a view. Is there a way to simulate the deceleration of the UIScrollView or

2条回答
  •  隐瞒了意图╮
    2021-01-03 11:55

    You would have to come up with an algorithm of some sort to calculate where you want the view to stop at depending on the velocity of the gesture, which can be obtained like this:

    CGPoint velocity = [panGesture velocityInView:panGesture.view];
    

    From there it should just be a matter of animating your view into its calculated resting place and adding an animation to get it there. I believe UIViewAnimationOptionCurveEaseOut would be appropriate here.

提交回复
热议问题