What actually happens when setCancelsTouchesInView is called?

I wonder what actually happens when I call setCancelsTouchesInView. This is not described in the white paper http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html

thanks

+7
source share
2 answers

ACB quotes the UIGestureRecognizer reference. To make it more specific, suppose you have a view with gestures attached, and you have these methods in your view controller:

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesBegan"); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesMoved"); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesEnded"); } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesCancelled"); } - (IBAction)panGestureRecognizerDidUpdate:(UIPanGestureRecognizer *)sender { NSLog(@"panGesture"); } 

And, of course, the calendar gesture recognizer is configured to send the panGestureRecognizerDidUpdate: message.

Now suppose you touch the view, just move your finger to recognize the panorama gesture, and then lift your finger. What does the application print?

If the gesture recognizer has cancelsTouchesInView set to YES , the application will record these messages:

 touchesBegan touchesMoved touchesCancelled panGesture panGesture (etc.) 

You can get more than one touchesMoved before canceling.

So, if you set cancelsTouchesInView to YES (by default), the system will cancel the touch before it sends the first message from the gesture recognizer, and you will not receive any more touch messages for that touch.

If the gesture recognizer has cancelsTouchesInView set to NO , the application will record these messages:

 touchesBegan touchesMoved panGesture touchesMoved panGesture touchesMoved panGesture (etc.) panGesture touchesEnded 

So, if you set cancelsTouchesInView to NO , the system will continue to send touch messages to touch gestures, alternating with gesture recognizer messages. The touch will end normally and not be canceled (if the system does not cancel the touch for any other reason, for example, pressing the home button while touching).

+29
source

From the Apple Developer Portal Link :

cancelsTouchesInView . If the gesture recognizer recognizes its gesture, it repels the remaining strokes of this gesture from their point of view (so the window will not deliver them). The window cancels previously delivered touches using the message (touchsCancelled: withEvent :). If the gesture recognizer does not recognize its gesture, the view gets an all-touching sequence with a few touches.

cancelsTouchesInView:

A boolean that affects what is delivered when the gesture is recognized.

@property (non-atomic) BOOL cancels TouchesInView

Discussion

When this property is YES (by default), and the receiver recognizes its gesture, touches of the same hardness that are expected, viewing is not delivered, and previously delivered touches are canceled using touchsCancelled: withEvent: the message was sent for viewing. If the recognizer does not recognize the gesture, or if the value of this property is NO, the view receives all touches in the multi-touch sequence.

+3
source

All Articles