0

我曾尝试在互联网上搜索有关此问题的信息,但无法提出解决我问题的解决方案。

我已经创建了一个子类,UITableViewCell我在其中添加UIScrollView了一个子视图,现在我希望scrollView 可以收听滚动手势,并且单击手势可以收听UItableView
同样使用这种布局是违背苹果的HIG的

4

2 回答 2

2

这是一个古老的问题,但由于我并没有真正找到一个好的答案,我想我会提供一个。这种方法直接捕获 UIScrollView(包含在表格单元格内)和 UITableView 单元格上的点击事件,并将它们传递给 UITableViewDelegate。它还允许您滚动 UIScrollView 内容,而无需传递滚动事件。不需要任何子类化。

  1. 在 ViewDidLoad 中,在 UITableView 上实例化一个 UITapGestureRecognizer
// Capture taps on scrollView fields and pass along to tableView
let tap = UITapGestureRecognizer(target: self, action: "tapIntercept:")
tableView.addGestureRecognizer(tap)
  1. 为上面的选择器创建一个回调函数
// Get the location of the table cell beneath the scrollView and pass the event off to the tableView
func tapIntercept(recognizer: UIGestureRecognizer) { 
    let point = recognizer.locationInView(tableView)
    if let indexPath = tableView.indexPathForRowAtPoint(point) {
        tableView(tableView, didSelectRowAtIndexPath: indexPath)
    }  
}
于 2015-07-11T15:17:44.213 回答
0

如果滚动视图是表格视图的子视图,您可以捕获手势并将其发送到其父视图,如下所示:

   - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [self.nextResponder touchesBegan:touches withEvent:event];
    }
于 2012-06-28T09:08:51.140 回答