Use the UITableView
method indexPathForRowAtPoint:
to determine which row at which the user stopped moving the image. Then cellForRowAtIndexPath
to get the cell, then the cell's center, then set the UIImageView
center to the cell center. Something like:
NSIndexPath *indexPath = [myTableView indexPathForRowAtPoint:touchPoint];
UITableViewCell *cell = [myTableView cellForRowAtIndexPath:indexPath];
myUIImageView.center = cell.contentView.center;
You could also animate the last statement so it moves to over the cell smoothly rather than jumping. Something like:
[UIView animateWithDuration:0.25 animations:^{
myUIImageView.center = cell.contentView.center;
}];
Inside of a gesture recognizer handler:
-(void)myGestureRecognizerHandler:(UIPanGestureRecognizer *)gestureRecognizer{
CGPoint touchPoint = [gestureRecognizer locationInView:myTableView];
NSIndexPath *indexPath;
UITableViewCell *cell;
switch ([gestureRecognizer state]) {
case UIGestureRecognizerStateBegan:
// Do stuff for UIGestureRecognizerStateBegan...
case UIGestureRecognizerStateChanged:
// Do stuff for UIGestureRecognizerStateChanged, e.g.,
myUIImageView.center = touchPoint;
case UIGestureRecognizerStateEnded:
indexPath = [myTableView indexPathForRowAtPoint:touchPoint];
cell = [myTableView cellForRowAtIndexPath:indexPath];
{
[UIView animateWithDuration:0.25f animations:^{
myUIImageView.center = cell.contentView.center;
}];
}
break;
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed:
default:
// Do stuff for cancelled/failed/...
break;
}
}