Search code examples
iphoneiosios4gesture-recognitioniphone-privateapi

Handling Touch Events on iOS devices


I am exploring the way touch events are handled on iOS devices. I referred the book: iOS Open Application Development. Working on that, I am overriding the mouseDown, mouseUp methods and simply displaying the co-ordinates in an alert box. However, the overridden methods never get called. The following is the code for the newView Class that derives from UIView:

-(void) _mouseDown: (GSEventRef) event{
CGPoint point =GSEventGetLocationInWindow(event);
UIAlertView* alert;
NSString* alertString =[NSString stringWithFormat: @"%f %f", point.x, point.y];
alert = [[UIALertView alloc] initWithTitle:@"Success" message:alertString delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}

-(BOOL) canHandleGestures{
return YES;
}

Is there any part that I missing ? Also, is there an alternative way of getting information on touch events and handling them ?


Solution

  • Better starting point would be here: https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/multitouch_background/multitouch_background.html

    These are the methods you may override in a UIView subclass:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event