UITableView从子视图中抓取触摸事件
问题描述:
我有一个UITableView,它将UIViews加载到它的单元格中。这些UIViews使用-touchesBegan:withEvent:等方法,这些方法都可以正常工作,让我实现代码以在表中移动这些子视图。这一切工作,直到我垂直移动我的手指&开始滚动表,然后UIViews停止接收任何触摸事件。如果有人知道如何解决这个问题,我会非常高兴!非常感谢。UITableView从子视图中抓取触摸事件
答
您的UITableView的父级UIScrollView可能会接管您的触摸事件。
只是forward事件到您的自定义子视图。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
//Your code here than should return if it reacts to touch
}
//forwarding action:
[self.nextResponder touchesBegan:touches withEvent:event];
}
答
-(void)ViewDidLoad
{
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
tapped.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapped];
[tapped release];
}
-(void)tapped
{
NSLog(@"TAPPED");
}
答
老话题,但我用同样的问题挣扎(UITableView的一个子视图的UITableView)。只需使用scrollEnabled = NO禁用“父”UITableView的滚动。这将停止垂直滚动。
谢谢你,但是当我开始垂直移动我的手指(即,它滚动表格并且不会将事件发送到我的子视图)时,我仍然无法阻止抓取触摸事件的表格。我会继续调查并回复,如果我找到如何做到这一点。 – SomaMan 2011-05-19 09:59:25