我试图模拟从UITableView拖放到UIView的图像。UITableView和UIView并排在同一个视图上。
我的方法:
是在touchesBegan中触发UITableView事件(即当一个单元格被触摸/选择时),并在触摸结束时在UIView中触发touchesEnded事件。
问题:
因此,我创建了一个自定义UITableViewCell,它包含一个UIImageView和几个UILabels。我为这个User Interaction Enabled设置了UIImageView。然后,为了接收touchesBegan事件,我在自定义UITableViewCell类中重写了touchesBegan方法;现在我能够从单元格接收touchesBegan事件。
问题是
当触摸结束在touchesEnded上时,我不会得到UIView事件。注意,我已经在视图控制器类中实现了touchesEnded方法(而不是在自定义类中);如果我在这个UIView中启动和停止触摸,就会看到touchesEnded正在被触发。
这里有我遗漏的东西吗?
使用Xcode 4.6 (4H127),在iPad 2上用iOS 6.1.3进行测试
发布于 2013-04-19 18:04:11
这是行不通的。您需要利用包含两个子视图的父视图上的触摸方法。可以抽象地看上去像这样:
-(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,如果触摸位于拖放对象的区域,那么返回父视图。
希望这能帮上忙
https://stackoverflow.com/questions/16109922
复制相似问题