简体   繁体   English

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

[英]Capture and stop propagation of user interaction iOS UITableViewCell

I am doing some custom drawing a UITableViewCell that I have subclassed. 我正在做一些自定义绘制我已经子类化的UITableViewCell。 In there there is an OpenGL ES 2.0 control that needs user interaction to work... now if I start dragging horizontally the control responds but as soon as I go in the vertical direction then it starts to move the table view's viewport. 在那里有一个OpenGL ES 2.0控件需要用户交互才能工作......现在如果我开始水平拖动控件会响应,但是一旦我沿垂直方向移动,它就会开始移动表视图的视口。 How do I stop this interaction from going to the UITableView and limit it to my own UIView in the UITableViewCell? 如何阻止此交互转到UITableView并将其限制在UITableViewCell中我自己的UIView?

I don't think you can prevent user interaction on the UITableView, since it would affect all the subviews. 我不认为你可以阻止UITableView上的用户交互,因为它会影响所有的子视图。
I'll try to send the UITableView interaction to the method you want it to use it. 我将尝试将UITableView交互发送到您希望它使用它的方法。

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

or use - (void)scrollViewDidScroll:(UIScrollView *)sender so that you can work on the sender's contentOffset to get the scrolling direction (see this post for more info about this) 或者使用 - (void)scrollViewDidScroll:(UIScrollView *)发送方,以便您可以处理发送方的contentOffset以获取滚动方向(有关此内容的详细信息,请参阅此帖子

You can try to subclass UITableView and override following methods 您可以尝试继承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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM