Unable to forward UITouch events to my view controller
I have a UISplitViewController setup with a custom view added as a subview of the view (UILayoutContainerView) of split view controller. I am trying to forward touch events from my custom view controller to the master and detail views, but the following (which was suggested here on another thread) seems to have no effect:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ UITouch *touch = [touches anyObject]; // Do something
[self.nextResponder touchesBegan:touches withEvent:event];
开发者_运维知识库
}
(I couldn't get this formatted properly)
As a result my custom view controller locks the events and all the UI underneath never has a chance to do anything.
How can I get my master and detail view controllers to receive events?
Edit: Even if I directly call the 4 touch methods on my detail view controller, the touches aren't properly processed.
If it's just a subview try to run:
[self.superview touchesBegan:touches withEvent:event];
That should pass it directly to the view above it.
While the Apple documentation says that a UIViewController should be in the that responder chain I've always had issues with getting that call to work. My solution has been to subclass UIView with a -(id) touchDelegate ivar and those methods above. Then just have those methods call up to the delegate. Dirty but it's been working for me.
Here's the official Apple doc if you're interested...
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html
I was able to get the touch events without interfering with the normal event flow by adding a UIGestureRecognizer
subclass to the split view controller's view.
From the docs:
UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews.
精彩评论