Detect multitasking gestures on iPad - iphone

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.

Related

What really happens when call setCancelsTouchesInView?

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.

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:)];
}
}
}

how to implement two fingers panning like safari broswer?

i try to implement panning and zooming functionality like safari browser in ipad.
i used UIPinchGestureRecognizer for zooming with two fingers touch. but i dont know how to implement two fingers panning.
when i touch with two fingers its tap count is 1.
please help.
thanks in advance.
You don't want the tapCount, you want the number of touches. If you touch down with two fingers you can two touch events each with a tap count of 1.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
[touches count] would return 2, one for each finger tip.
Read through the apple guide for touch events

reliable way to get iPhone touch input?

I started using the MoveMe sample to get touch input working.
basically, I define these two callback functions to get my touch input:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch* touch in touches )
{
printf("touch down");
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch* touch in touches )
{
printf("touch up");
}
}
This works fine, until you have more than 5 touches on the screen at once. then it stops working properly, you won't get the "touch down" message if there are more than 5 touches on the screen. what is even worse is that you won't reliably get all of the "touch up" messages until you have removed ALL your fingers from the screen.
If you touch with 6 fingers, then release 3, then touch again with the other 3 still down, you will get the "touch down" but if you release it, some times you get the "touch up" sometimes you don't.
This pretty much makes it impossible to track touches, and usually results in a touch getting 'stuck' permanently down, when passed to my Touch Manager.
Are there some better apis to use to get touch input? is there at very least a function you can call to reliably get whether the screen is currently touched or not? that way I could reset my manager when all fingers are released.
EDIT:
right, there must be something I'm missing. because currently the calculator does something I cannot do with those callbacks.
it only accepts one touch at a time, if there is more than one touch on the screen it "cancels" all touches, but it must keep track of them to know that there is "more than one" touch on the screen.
if I touch the screen the button goes down, now if I add another touch to the screen, the button releases, cool, not allowed more than one touch. now, if I add 4 more fingers to the screen, for a total of 6, the screen should break, and when I release those 6 fingers, the app shouldn't get any of the "up" callbacks. yet when I release all of them and touch again, the button depresses, so it knows I released all those fingers!! how??
The problem you have is that the iPhone and iPod touch only support up to five touches at the same time (being fingers still touching the screen). This is probably a hardware limit.
(As St3fan told you already.)
The system will cancel all touches if there are more than 5 at the same time:
touchesCancelled:withEvent:
(This is probably what causes the odd behavior with only some touches calling touchesEnded:withEvent:)
If you want to know if a touch ended and it ended because it was lifted then make sure to check the UITouch's phase property.
It stops working because 5 is the max amount of touches that the iPhone and iPod currently support. No way around that I'm afraid.

What happens when dragging off screen?

I have an object that can be dragged around. Once the user's finger goes off screen and comes back, I loose the ability to drag the object. If the user then does another touch and drag, everything is fine.
How can I get notified once the user's finger drags back onto the screen? Since touchesBegan doesn't fire, I don't get any notification.
Here is my touchesMoved, which I call in the touchesBegan:
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
//stop object dragging at edge of screen
if(location.x > 35){
myboject.center = location;}
}
The described behaviour seems normal to me, and all built-in Apple apps behave the same way. Since there’s no touch screen outside of the touch screen (yep), I believe there’s no way the device can distinguish between touch beginning or moving from outside of the screen.