What really happens when call setCancelsTouchesInView? - iphone

Wondering what really happens when i call setCancelsTouchesInView. It is not covered in the official document http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html
Thanks

ACB quoted the UIGestureRecognizer reference. To make it a little more concrete, suppose you have a view with a pan gesture recognizer 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 pan gesture recognizer is configured to send the panGestureRecognizerDidUpdate: message.
Now suppose you touch the view, move your finger enough for the pan gesture to be recognized, and then lift your finger. What does the app print?
If the gesture recognizer has cancelsTouchesInView set to YES, the app will log these messages:
touchesBegan
touchesMoved
touchesCancelled
panGesture
panGesture
(etc.)
You might get more than one touchesMoved before the cancel.
So, if you set cancelsTouchesInView to YES (the default), the system will cancel the touch before it sends the first message from the gesture recognizer, and you won't get any more touch-related messages for that touch.
If the gesture recognizer has cancelsTouchesInView set to NO, the app will log these messages:
touchesBegan
touchesMoved
panGesture
touchesMoved
panGesture
touchesMoved
panGesture
(etc.)
panGesture
touchesEnded
So, if you set cancelsTouchesInView to NO, the system will continue sending touch-related messages for the gesture touch, interleaved with the gesture recognizer's messages. The touch will end normally instead of being cancelled (unless the system cancels the touch for some other reason, like the home button being pressed during the touch).

From the apple developer portal link:
cancelsTouchesInView — If a gesture recognizer recognizes its gesture,
it unbinds the remaining touches of that gesture from their view (so
the window won’t deliver them). The window cancels the previously
delivered touches with a (touchesCancelled:withEvent:) message. If a
gesture recognizer doesn’t recognize its gesture, the view receives
all touches in the multi-touch sequence.
cancelsTouchesInView:
A Boolean value affecting whether touches are
delivered to a view when a gesture is recognized.
#property(nonatomic) BOOL cancelsTouchesInView
Discussion
When this
property is YES (the default) and the receiver recognizes its gesture,
the touches of that gesture that are pending are not delivered to the
view and previously delivered touches are cancelled through a
touchesCancelled:withEvent: message sent to the view. If a gesture
recognizer doesn’t recognize its gesture or if the value of this
property is NO, the view receives all touches in the multi-touch
sequence.

Related

Detect multitasking gestures on iPad

In my iPad app,
If any app is running we can move the app horizontally by dragging the app screen horizontally by two or three fingers.
It is an inbuilt feature of an iPad, right.
Is there any notification or somethig so that I can be notified? When this happens.
Is there any way so that Ican disable this feature for my app.?
Code:-
WHILE TOUCHES MOVED CALL MY MAIN VIEW IS DISABLED AS REQUIREMENT, SO WHEN I AM DRAGGING THE SCREEN AS DESCRIBED ABOVE EVERYTHING FREEZS.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if(self.tag==trackCell && (trackLifeCycle==1 || trackLifeCycle==2) && trackCell!=-2)
{
if(![[self superview] isKindOfClass:[AQGridView class]])
{
//NSLog(#"Touches Moved");
trackLifeCycle=2;
//////NSLog(#"Touches Moved at cell Starts%d",self.tag);
UITouch *T=[touches anyObject];
self.center=[T locationInView:[self superview]];
[delegate isOnHeaderView:self center:self.center];
//////NSLog(#"Touches Moved at cell Ends %d",self.tag);
}
}
}
The multitasking gestures use four or five fingers. You cannot disable them from within your app. The user can disable them for all apps in the Settings app (under the General section).
There is no notification specifically for the multitasking gestures. You will get UIApplicationWillResignActiveNotification when the user begins the gesture. If the user ends the gesture without switching apps, you will get UIApplicationDidBecomeActiveNotification. If the user does switch apps, you will get UIApplicationSuspendedNotification (which might not be public) and UIApplicationDidEnterBackgroundNotification.
If you had active touches when the user began the multitasking gesture, each touched view should get a touchesCancelled:withEvent: message, and each active gesture recognizer should set its own state to UIGestureRecognizerStateCancelled and send its action messages.

UIGestureRecognizer that cancels when touchup outside of targetView

I have a UIView of which I want to know when the user is doing:
touchDownInside (to highlight the view)
touchUpInside (to confirm the action)
touchUpOutside (to cancel and reset the hightlight)
what gestureRecognizer can do this for me?
Please go though these four methods also which your view can override to handle the four distinct touch events:
1) finger or fingers touches the screen
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
2)finger or fingers move across the screens(this message repeatedly as a finger moves.)
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
3)finger or fingers is removed from the screen
-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
4) a system event,interrupts a touch before it ends
-(void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;
You can do this implementing the touches methods itself, why do you need gesture recognizer?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
The above function for touch down.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
The above function for touch up. And the combination of both for cancel.

How to implement touch events in uiwebview?

I have tried various solutions provided on this site and others to implement touch events on uiwebview. But still I am not able to do this. Actually, i have created a article reader application. Here, I have added a uiwebview on the normal uiview. Now, I want to trace some user touch events on that particular webview.
When I do this on normal view, it works perfectly. But if I try it on webview. it stops working.
The solutions I tried before are
implementing touch methods like
touchbegan
touchended
touchmoved
touch cancelled
2 implementing uigesturerecognizer
3 implementing window touch events like send event
Now If anyone can help me or tell me where I am doing wrong or a new solution(other than this), then I will be thankful.
Put a transparent UIVIew on top of your UIWebView to capture touches. You can then act on them or optionally pass them down to the UIWebView using the touchesBegan deletage method.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.myUIWebView touchesBegan:touches withEvent:event];
}
Check this previous post for details: iOS - forward all touches through a view
I subclassed UIWebView and just "leeched" onto its gesture recognizers in subviews 2 levels deep (you could go recursively but thats enough for iOS6-7).
Then you can do whatever you want with the touch location and gesture recognizer's state.
for (UIView* view in self.subviews) {
for (UIGestureRecognizer* recognizer in view.gestureRecognizers) {
[recognizer addTarget:self action:#selector(touchEvent:)];
}
for (UIView* sview in view.subviews) {
for (UIGestureRecognizer* recognizer in sview.gestureRecognizers) {
[recognizer addTarget:self action:#selector(touchEvent:)];
}
}
}

difference between touchMoved and Swipe?

i am rotating circle in iPad.i have inserted swipegesture event.but I want to different operations in touchMoved and swipeEvent.but when I do touch moving , swipw gesture is called, what i have to do , any help please?
swipe:
NSEventTypeSwipe
An event representing a swipe gesture.
Available in Mac OS X v10.6 and later.
Declared in NSEvent.h.
and
touchMoved:
Sent to the receiver when one or more fingers move in the associated view.
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
so swipe cant be use to code some thing when any thing happens like touches.swipe is use for recognizing touch event.

UIScrollView - detect second touch while scrolling

I have a subclass of UIScrollView that implements this method:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"touches: %d", [[event allTouches] count]);
[self.nextResponder touchesBegan:touches withEvent:event];
}
This gets called when I first touch the scroll view. However, if I begin dragging the scroll view, then place a second finger down, touchesBegan does not get called. I need to detect when a second touch has occured in the scrollview, even if it is currently scrolling. Any ideas?
EDIT: Two touches are registered if I start with two, but if I start with one, begin scrolling, then put a 2nd finger down it is not registered.
Make sure multipleTouchEnabled is set to YES on your scroll view.
You can also set this in Interface Builder. Look for 'Multiple Touch' checkbox.