从UITableView拖动按钮

时间:2011-05-24 11:57:30

标签: ipad ios4 uitableview uigesturerecognizer

我有一个由自定义单元格组成的TableView。此单元格包含标签和按钮。现在我在单元格中的按钮上添加了 panGestureRecognizer 我的问题是当我尝试开始移动/拖动按钮时,按钮正确移动但不幸的是按钮获得了隐藏在TableView后面。我怎样才能让它摆在面前呢。自定义单元格是以编程方式创建的,TableView也是如此。我的手势处理方法如下:


-(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];

}

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];
该代码已根据Apple的代码here

进行建模

1 个答案:

答案 0 :(得分:0)

此解决方案:Drag an UIImageView from UIscrollView to another view

希望这会有所帮助