简体   繁体   中英

Pass touch events from UIView on top of UITableView

I'm trying to build a custom table view with a UIView overlaying it. 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).

I currently have a custom UITableViewController, as well as a custom 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).

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.

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.

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

     [_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.

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.

Thanks!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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