Reputation: 2493
As the Apple document says that, the process to handle a gesture is
The initial view attempts to handle the event or message. If it can’t handle the event, it passes the event to its superview, because the initial view is not the top most view in its view controller’s view hierarchy.
The superview attempts to handle the event. If the superview can’t handle the event, it passes the event to its superview, because it is still not the top most view in the view hierarchy.
The topmost view in the view controller’s view hierarchy attempts to handle the event. If the topmost view can’t handle the event, it passes the event to its view controller.
The view controller attempts to handle the event, and if it can’t, passes the event to the window.
If the window object can’t handle the event, it passes the event to the singleton app object.
If the app object can’t handle the event, it discards the event.
However, in my case, I have a subclass of UITableViewController as the root vc of window, and add a view to cover the whole screen as following:
@interface MyTableViewController : UITableViewController()
@end
@implementation MyTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *redView = [[UIView alloc] initWithFrame:self.view.bounds];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
}
I think that the redView will be the hit-test view if I touch the screen to generate a pan gesture, and because the redView can't handle it,it will pass the touch event to its superview, which is also the superview of tableView. As a result, the tableview will not handle pan gesture. However, the tableView could still handle the pan gesture , could anyone explain it ?
Upvotes: 0
Views: 531
Reputation: 725
If somebody still looking for a more simple solution here is it : The UItableView has a property named panGestureRecognizer so in the upper view you simply write this code :
[self.upperView addGestureRecognizer:self.tableView.panGestureRecognizer];
so the table scrolling events gets passed to the table view
Upvotes: 1
Reputation: 437632
If your view controller is a UITableViewController
, the superview
of redView
would be the UITableView
, so when redView
doesn't handle the gesture, it's passed to its superview
, so the UITableView
receives (and processes) the gesture.
Upvotes: 2