iPhone - how to track touches and allow button taps at the same time?
Posted
by Jonathan Cohen
on Stack Overflow
See other posts from Stack Overflow
or by Jonathan Cohen
Published on 2010-04-17T10:31:28Z
Indexed on
2010/04/17
10:33 UTC
Read the original article
Hit count: 366
I'm wondering how to track touches anywhere on the iPhone screen and still have UIButtons respond to taps.
I subclassed a UIView, made it full screen and the highest view in the hierarchy, and overrode its pointInside:withEvent method. If I return YES, I'm able to track touches anywhere on the screen but the buttons don't respond (likely because the view is instructed to handle and terminate the touch). If I return NO, the touch passes through the view and the buttons respond, but I'm not able to track touches.
Do I need to subclass UIButton or is this possible through the responder chain? What am I doing wrong?
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return NO;
}
//only works if pointInside:withEvent: returns YES.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"began");
[self.nextResponder touchesBegan:touches withEvent:event];
}
//only works if pointInside:withEvent: returns YES.
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"end");
[self.nextResponder touchesEnded:touches withEvent:event];
}
© Stack Overflow or respective owner