Friday, 27 September 2013

UIGestureRecognizer with a touch moving off UIView

UIGestureRecognizer with a touch moving off UIView

I have a UILongPressGestureREcognizer with a minimum press length of 0
seconds. On UIGestureRecognizerStateStart I alter the UIView. On
UIGestureRecognizerStateEnded, I run the code for what ever the press is
suppose to do.
-(IBAction)longPressDetected:(UILongPressGestureRecognizer *)recognizer {
static NSTimer *timer = nil;
if (recognizer.state == UIGestureRecognizerStateBegan) {
// alter look of UIView
}
else if (recognizer.state == UIGestureRecognizerStateEnded) {
// do something
// change look back to original state
}
}
I am running into an issue where if the touch starts on the UIView and if
the touch is dragged outside of the UIView and is lifted, the
UIGestureRecognizerStateEnded still fires.
I need to be able to handle a touch inside the UIView, the user drag
outside of the UIView and to cancel it.
I know a UIButton can do it, but it does not fulfill all the needs I have.
How can I cancel a touch if the touch is dragged outside of the UIView?

No comments:

Post a Comment