0

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 ?

Hrishikesh_Pardeshi
  • 995
  • 4
  • 19
  • 45

3 Answers3

4

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
fractalwrench
  • 4,028
  • 7
  • 33
  • 49
calimarkus
  • 9,955
  • 2
  • 28
  • 48
3

You can use :

- (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 {}

for getting touch events from UIView subclass.

Vikram Pote
  • 5,433
  • 4
  • 33
  • 37
arun.s
  • 1,528
  • 9
  • 12
1

You Have to use gesturerecognizer (like uitapgesturerecognizer, uiswipegesturerecognizer or UITouch events)

Red Mak
  • 1,176
  • 2
  • 25
  • 56