Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS view controller containment | Child View Controller passes touches to Parent View Controller

In iOS5, I use UIViewController containment all over an app where I have implemented UITouchGesture in several places.

When I add a child ViewController (Full Screen) the touches are passed down to its parent.

What, if any, is the solution around this. I use MPFlipViewController and I can see the page turning underneath the child when the user moves their finger across the the Child ViewController.

For clarification, I add my ViewController as a child with the following:

[self addChildViewController:vc];
[vc willMoveToParentViewController:nil];
[self.container addSubview:vc.view];
[vc didMoveToParentViewController:self];

The container is merely just a UIView that the view of the childViewController & other UIView objects sit on. Thanks

like image 728
theiOSDude Avatar asked Jan 11 '23 08:01

theiOSDude


1 Answers

You've got it backwards. Controller containment is one thing, but this is just standard view hierarchy and responder chain stuff. So the touches are initially sent to the parent; specifically a call is made to its view's -(UIView *)hitTest:withEvent:. That returns a child view if one can be found. Otherwise it returns one of its own views. Possibly it returns itself.

If a touch is being captured by the parent controller that means it's never been sent to the child. Not that it's being sent to the child then ascending up to the parent.

If you want the parent to do something unusual with touch capture then just use a custom view and implement your own -hitTest:withEvent:. As a first step, do that and just log the inputs to see what happens.

like image 80
Tommy Avatar answered Jan 25 '23 23:01

Tommy