I am trying to figure out the logic for dragging a view, then making the drag slow down exponentially when it reaches a certain point. I have sort of got it working, albeit buggy and a bit hacky. I wondered if there was a better formula I could use instead of newPosition = (-kDeleteViewWidth + (point.x * 0.2));
Full gesture code as below.
// kDeleteViewWidth is defined as 80.0f
UIPanGestureRecognizer *gesture = (UIPanGestureRecognizer *)sender;
CGPoint point = [gesture translationInView:self];
if ([gesture state] == UIGestureRecognizerStateBegan)
_initialPosition = _topView.frame.origin;
if ([gesture state] == UIGestureRecognizerStateChanged)
{
// Hacky Elastic method
float newPosition = _initialPosition.x + point.x;
if (point.x < -kDeleteViewWidth)
newPosition = (-kDeleteViewWidth + (point.x * 0.2));
[_topView setFrame:CGRectMake(newPosition, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
}
For the sake of completeness, heres the code I went with: