捕获并停止用户交互iOS UITableViewCell的传播

时间:2011-08-05 10:13:14

标签: ios uitableview opengl-es-2.0 user-interaction

我正在做一些自定义绘制我已经子类化的UITableViewCell。在那里有一个OpenGL ES 2.0控件需要用户交互才能工作......现在如果我开始水平拖动控件会响应,但是一旦我沿垂直方向移动,它就会开始移动表视图的视口。如何阻止此交互进入UITableView并将其限制为UITableViewCell中我自己的UIView?

2 个答案:

答案 0 :(得分:1)

我认为您不能阻止UITableView上的用户交互,因为它会影响所有子视图 我将尝试将UITableView交互发送到您希望它使用它的方法。

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
   [MyClass myScrollDidStartMethod]; 
}

或使用 - (void)scrollViewDidScroll:(UIScrollView *)发送者,以便您可以处理发件人的contentOffset以获取滚动方向(有关此内容的详细信息,请参阅this post

答案 1 :(得分:1)

您可以尝试继承UITableView并覆盖以下方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
    UITouch *touch = [touches anyObject];

    // if user tapped on your custom view, disable scroll        
        self.scrollEnabled = NO;
    // end if

    [super touchesBegan:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    self.scrollEnabled = YES;
    [super touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    self.scrollEnabled = YES;   
    [super touchesCancelled:touches withEvent:event];
}