How can I programmatically determine if a touchUpInside event has occurred?
It seems like if this method gets called anytime the user touches my view:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == self && [touch tapCount] >= 1) {
// do something...
}
}
I have implemented this in UIScrollView. The documentation for UIEvent does not mention those touchUpInside, touchUpOutside, etc. events that are available in Interface Builder when connected to action methods.
Actually, I want the method to be called on only one of these touchUpInside events, not on any touch.
+1
a source to share
4 answers
Wadoff's technique is neat, however remember to clear the sensory event by triggering the super function. Here is the complete code.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
BOOL touchedUpInside = NO;
if (self.isTouchUpInside) {
touchedUpInside = YES;
}
[super touchesEnded:touches withEvent:event];
if (touchedUpInside) {
// touched up inside
}
}
0
a source to share