简体   繁体   English

从UITableView顶部的UIView传递触摸事件

[英]Pass touch events from UIView on top of UITableView

I'm trying to build a custom table view with a UIView overlaying it. 我试图建立一个UIView覆盖它的自定义表视图。 I'm trying to recognize a special gesture on the regular UIView, specifically a pan gesture that takes a double tap to activate it (tap and hold, then pan). 我正在尝试识别常规UIView上的特殊手势,特别是需要双击以激活它的平移手势(点住并按住,然后平移)。

I currently have a custom UITableViewController, as well as a custom UIView. 我目前有一个自定义UITableViewController,以及一个自定义UIView。 I'd like to try to keep it as a UITableViewController instead of a UITableView inside a UIViewController for compatibility reasons (easy replacing of existing UITableViewControllers). 出于兼容性原因,我想尝试将其保留为UITableViewController而不是UIViewController中的UITableView(轻松替换现有的UITableViewControllers)。

I can get a double tap and pan no problem, but the issue is I can no longer actually SELECT a row in the table view. 我可以双击并平移没有问题,但是问题是我不再能够在表视图中实际选择一行。 I can scroll within the table, but actual selections do not work. 我可以在表格中滚动,但实际选择不起作用。

Ideally, I'd like to be able to retain all taps, swipes, and regular events in any custom table view cells (for example, Clear or Mailbox where you can swipe left or right to activate a specific action). 理想情况下,我希望能够在所有自定义表格视图单元格中保留所有点击,滑动和常规事件(例如,“清除”或“邮箱”,您可以在其中向左或向右滑动以激活特定操作)。

I know that I can get the table view cell from the method indexPathForRowAtPoint: from the table view, but that will only allow me to select the toggle. 我知道我可以从表视图的indexPathForRowAtPoint:方法中获取表视图单元格,但这仅允许我选择切换。

I've also tried to override the touches began like this: 我也尝试覆盖像这样开始的接触:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.nextResponder touchesBegan: touches withEvent: event];
}

as well as other associated events, and have confirmed that nextResponder is the custom UITableViewController, but have not been able to do anything. 以及其他相关事件,并已确认nextResponder是自定义UITableViewController,但无法执行任何操作。

I checked into a bunch of other posts but no solutions have worked for me. 我查看了许多其他帖子,但没有解决方案对我有用。 Some other things I have tried are: 我尝试过的其他一些事情是:

  • Adding a single tap gesture recognizer and forwarding it to the UITableViewController 添加一个点击手势识别器并将其转发到UITableViewController

     [_containingTableViewController gestureRecognizerShouldBegin: tapGesture]; 
  • Implemented different gesture recognizer delegates 实现了不同的手势识别器委托

     -(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch: (UITouch *)touch{ return ( touch.tapCount >= 2 ); } 

    As well as both YES and NO for: 以及是和否:

     -(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 

Also, on the table view I've tried setting canCancelContentTouches but neither value works. 另外,在表格视图上,我尝试设置canCancelContentTouches但是没有一个值起作用。

Any help would be greatly appreciated, I have tried quite a bunch but just can't get it! 任何帮助将不胜感激,我已经尝试了很多,但就是不明白!

I may be able to post the full project on GitHub if it really needs to be done, but I'll have to clean it up a tad first. 如果确实需要完成整个项目,我可以在GitHub上发布整个项目,但是我必须先清理一下。

Thanks! 谢谢!

我不明白您的麻烦,所以不确定是否可以帮到您,但是您可以使用setUserInteractionEnabled *的UIViewUITableView等方法的FALSE/NO禁用它的任何类型的事件。

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

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