Another problem with UIResponder and event delivery
I'm trying to implement a UIResponder object that will allow me to record screen activity, then pass the event on to the next responder to allow the application to proceed as normal. I've been researching this for a while now and see two ways that should work: Either create a root view and ignore touches in the subviews placed on top of it, allowing the root view to handle them; OR create a GestureRecognizer which is added to all the subviews. My application has multiple views that are swapped in and out on the main window.
I've tried both methods and end up at the same impasse: I get the touchesBegan/touchesMoved/touchesEnded events in my view (or Recognizer), but nothing happens when I send them down the responder chain. I've tried all of the following. Note that 'view' is derived from touch.view and view.superview is my 'loginView' object, which contains the button that was tapped to get me here:
[view hitTest:frame.origin withEvent:event];
[view touchesBegan:touches withEvent:event];
[view.superview hitTest:frame.origin withEvent:event];
[view.superview tou开发者_高级运维chesBegan:touches withEvent:event];
[[view nextResponder] touchesBegan:touches withEvent:event];
[[view nextResponder] hitTest:frame.origin withEvent:event];
[[[view superview] nextResponder] touchesBegan:touches withEvent:event];
[[view superview] hitTest:frame.origin withEvent:event];
None of these work, and in fact '[[view nextResponder] hitTest...' generates a warning.
I've tried resignFirstResponder, and was even going to try a sendAction, but I'm just grasping at straws at this point. I've tried putting my view at both the bottom and top of the chain and get the same results. Obviously I'm missing something, but I can't see what.
Can anyone give me a clue as to what to try next?
-- Sam
I'm not really sure what exactly you're a trying to do, but maybe http://iphonedevelopment.blogspot.com/2008/10/bit-about-responder-chain.html helps you.
Personally, what I'm doing in a UIView subclass to pass the touches around is this:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[[self nextResponder] touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[[self nextResponder] touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[[self nextResponder] touchesEnded:touches withEvent:event];
}
精彩评论