0

我正在尝试模仿将图像从 a 拖放UITableView到 a UIView。UITableView 和 UIView 都在同一个视图上,并排。

我的做法:

是触发touchesBegan内部的事件UITableView(即,当触摸/选择单元格时)并在触摸结束时触发 touchesEnded 事件UIView

问题:

所以我创建了一个自定义UITableViewCell,其中包含一个UIImageView和几个UILabels. 我User Interaction Enabled为此设置了UIImageView. 然后为了接收touchesBegan事件,我确实覆盖touchesBegan了自定义UITableViewCell类中的方法;现在我可以touchesBegan从单元格接收事件。

问题是

当触摸touchesEndedUIView. 请注意,我已经touchesEnded在视图控制器类中实现了该方法(不是在自定义类中);如果我在此范围内开始和停止触摸UIView,我会看到touchesEnded被解雇。

我在这里有什么遗漏吗?

使用 Xcode 4.6 (4H127),在 iPad 2 和 iOS 6.1.3 上测试

4

1 回答 1

0

这不会那样工作。您将需要在包含两个子视图的父视图上使用触摸方法。可以抽象地看起来像这样:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    if ([self touchOnCell:touches]) { //check to see if your touch is in the table
        isDragging = YES;             //view cell
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    //do your dragging code here
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    if (isDragging && [self touchOnDropView:touches]) {
        //do your drop code here 
    }
}

现在,如果这不能单独工作,您可能希望hitTest在 tableView 上实现,并且如果触摸位于拖动对象的区域,则返回父视图。

希望这可以帮助

于 2013-04-19T18:04:11.117 回答