【问题标题】:touchesBegan in custom UITableViewCell, touchesEnded in UIViewtouchesBegin 在自定义 UITableViewCell,touchesEnded 在 UIView
【发布时间】:2013-04-19 17:04:32
【问题描述】:

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

我的做法:

是在UITableView 中触发touchesBegan 事件(即当触摸/选择一个单元格时)并在UIView 中结束触摸时触发touchesEnded 事件。

问题:

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

问题是

当触摸在UIView 上结束时,我没有收到touchesEnded 事件。请注意,我已经在视图控制器类中实现了touchesEnded 方法(不是在自定义类中);如果我在这个UIView 中开始和停止触摸,我会看到touchesEnded 被解雇。

这里有什么我遗漏的吗?

使用 Xcode 4.6 (4H127),在装有 iOS 6.1.3 的 iPad 2 上进行测试

【问题讨论】:

    标签: ios uitableview uiview touchesbegan


    【解决方案1】:

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

    -(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 
        }
    }
    

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多