Skip to content

Instantly share code, notes, and snippets.

@davidkatz
Created April 29, 2014 11:25
Show Gist options
  • Save davidkatz/11397404 to your computer and use it in GitHub Desktop.
Save davidkatz/11397404 to your computer and use it in GitHub Desktop.
// calculate final required offset
int initialImageCenter = rectInTableView.origin.y + rectInTableView.size.height/2;
int screenWidth = [UIScreen mainScreen].bounds.size.width;
int currentDistanceFromCenter = screenWidth/2 - initialImageCenter;
int finalHorizontalOffset = currentDistanceFromCenter;
// calculate current offset based on drag position
int maxDragDistance = 100; // say we want the animation to complete while the finger drags up to 100 pixels
int currentDragRatio = currentDragDistance / maxDragDistance // assuming currentDragDistance is available
int currentHorizontalOffset = currentDragRatio*finalHorizontalOffset
[self.tableView setContentOffset:CGPointMake(0, currentHorizontalOffset];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment