Gesture recognizer for mouse down and up in iPhone SDK
Posted
by
user545201
on Stack Overflow
See other posts from Stack Overflow
or by user545201
Published on 2010-12-16T20:31:11Z
Indexed on
2010/12/22
21:54 UTC
Read the original article
Hit count: 217
I want to catch both mouse down and mouse up using gesture recognizer. However, when the mouse down is caught, mouse up is never caught.
Here's what I did:
First create a custom MouseGestureRecognizer:
@implementation MouseGestureRecognizer
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
self.state = UIGestureRecognizerStateRecognized;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
self.state = UIGestureRecognizerStateRecognized;
}
@end
Then bind the recognizer to a view in view controller:
UIGestureRecognizer *recognizer = [MouseGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.view addGestureRecognizer:recognizer];
When I click mouse in the view, the touchesBegan is called, but touchesEnded is never called. Is it because of the UIGestureRecognizerStateRecognized?
Any advice will be appreciated! Thanks!
© Stack Overflow or respective owner