I have a TableView made up of a custom cell. This cell contains a label and a button. Now I have a panGestureRecognizer added to the button in the cell. My problem is when I try to start moving/dragging the button, the button moves correctly but unfortunately the button gets hidden behind the TableView. How can I make it to come in front of it. The custom cell is created programmatically and so is the TableView. My gesture handling method is as follows:
-(void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer withEvent:(id) event
{
UIView *piece = [gestureRecognizer view];
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
//*******************Dragging Ended*************************************
if([gestureRecognizer state]==UIGestureRecognizerStateEnded)
{
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
//*******************Dragging Started andchanged*************************************
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] ==UIGestureRecognizerStateChanged)
{
CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
[piece setCenter:CGPointMake([piece center].x + translation.x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
CGPoint moveLocation=[gestureRecognizer locationInView:piece];
NSIndexPath *indexPath=[tableView indexPathForRowAtPoint:moveLocation];
}
-(void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan || (gestureRecognizer.state == UIGestureRecognizerStateChanged))
{
UIView *piece = gestureRecognizer.view;
CGPoint locationInView = [gestureRecognizer locationInView:piece];
CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview];
piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
piece.center = locationInSuperview;
}
}
The code has been modelled based on apple's code here