Transfer touch to parent view without disabling user interaction with child view

I have a UIView on a view controller view. UIView added a panorama gesture. Now I want to transfer the touch to the parent view (view controller view) so that the touches of delegation methods are also called by the parent view, as well as the UIView.

+4
source share
1 answer

Depends on what you want to do. If you want the view manager to know that something has happened in the child of the UIView, you must pass the delegate of the main view controller to the child view (object-oriented programming path). Something like that:

// in child UIVIew 
...
id<mainControllerDelegate> _mainControllerDel; // This delegate was passed to the view by the main view controller 
...
-(void)gestureHappened
{
 [_mainControllerDel gestureHappenedInView];
}

But if you want both views to respond to the gesture, you should use the gesture delegation method shouldRecognizeSimultaneouslyWithGestureRecognizer , for example:

// In class that conforms to your UIGestureRecognizerDelegate 
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
     return YES; 
}

EDIT:

, touchesBegan ( ), . . , iOS. , , . :

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

, , :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   [_mainControllerDel touchBeganOnView: self withEvent: event];
}
+4

All Articles