I am trying to recognize when two fingers are being swiped simultaneously. I started with the "Swipes" sample code from the Beginning iPhone Development Book. Run by itself it seems to work fine. Once I integrate it into my application, it only can recognize a single finger swipe.
I have triple checked that I pulled over the relevant code. I've tried both the simulator and my phone (same results). It can recognize and differentiate between a horizontal or vertical swipe. It doesn't recognize anything more than a single finger. Doesn't produce any errors or warnings.
I thought maybe I was obscuring the swipe detection with a label, graphic, or view, but I suspect if that were the case it wouldn't detect be detecting a single swipe.
I also tried commenting out a repeating animation that I have, thinking maybe it was interrupting the detection of a second finger. That didn't change anything.
Been struggling with this off and on for a few days now. Any suggestions would be greatly appreciated.
PS-Based on the sample code, the output from detecting multiple swipes is an addition to a text string displayed in a label. It will say "double" or "triple" in addition to "vertical swipe detected". So perhaps I should clarify that I am not seeing a result that displays the "double" or "triple" text output in this label, and thus assuming the extra swipe is not being detected.
Last edited by DenVog; 02-14-2009 at 01:49 PM.
Reason: Added PS Clarification
No one else has run into this? I'd really appreciate any insight that could be shared. Quite frustrating and I've pretty much exhausted the troubleshooting paths I can think of. Thanks for any help.
I did not know if it would be cool for me to post the code here, as it's basically cut-and-paste from the Beginning iPhone Development Book Chapter 13 Swipes sample that is already online.
Beyond those chunks, I'm not sure what to post short of putting my whole project up here. Is there something in particular I can share that would help? Something that would cause a conflict, interrupt, and/or the ordering of statements?
I did not know if it would be cool for me to post the code here, as it's basically cut-and-paste from the Beginning iPhone Development Book Chapter 13 Swipes sample that is already online.
Beyond those chunks, I'm not sure what to post short of putting my whole project up here. Is there something in particular I can share that would help? Something that would cause a conflict, interrupt, and/or the ordering of statements?
Thanks for your attention.
make sure you have your view set to receive multi-touch events, otherwise the iPhone will only send you info about the first finger... if you're using Interface Builder, it's a checkbox for the view. otherwise you can do it in code as well.
make sure you have your view set to receive multi-touch events, otherwise the iPhone will only send you info about the first finger... if you're using Interface Builder, it's a checkbox for the view. otherwise you can do it in code as well.
Ha! That was it. For all the poking, searching, and trial and error I did in my code, it was a checkbox in interface builder. I feel very silly, but am grateful to know the answer. Thanks very much for taking time to respond.
What's the saying about the most obvious solution?
Ha! That was it. For all the poking, searching, and trial and error I did in my code, it was a checkbox in interface builder. I feel very silly, but am grateful to know the answer. Thanks very much for taking time to respond.
What's the saying about the most obvious solution?
Do anyone know how to achieve this , without using IB.
I sort of forgot about this thread for a while, but finally came back to it. I did get the multi-fingered swipes to work. I am guessing that there is a much easier way to do this, but apple has no documentation for it .
Here is the viewController.h file
Code:
//
// TwoFingerSwipe.h
//
//
// Created by Cameron C Cohen on 9/2/09.
// Copyright 2009 CCC Development, LLC. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TwoFingerSwipe : UIViewController {
CGPoint touchDownLocation;
CGPoint touchUpLocation;
}
@property (nonatomic) CGPoint touchUpLocation;
@property (nonatomic) CGPoint touchDownLocation;
- (void) detectSwipe;
@end
And here is the viewController.m file
Code:
//
// TwoFingerSwipe.m
//
//
// Created by Cameron C Cohen on 9/2/09.
// Copyright 2009 CCC Development, LLC. All rights reserved.
//
#import "TwoFingerSwipe.h"
@implementation TwoFingerSwipe
@synthesize touchUpLocation, touchDownLocation;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches began");
//create a touch
UITouch *touchDown = [touches anyObject];
//only detect touch if there is two fingers
if ([touches count] == 2)
{
NSLog(@"two fingers touched");
//create a CGPoint which gives us the X and Y location of the touch
touchDownLocation = [touchDown locationInView:self.view];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches ended");
//create a touch
UITouch *touchUp = [touches anyObject];
//only detect touch if there are two fingers
if ([touches count] == 2) {
NSLog(@"Two fingers ended");
//create CGPoint that gives us the X and Y values of the touch
touchUpLocation = [touchUp locationInView:self.view];
[self detectSwipe];
}
}
//create the code that detects if there is a swipe. there is probably an easier way
//to do this, but this is the only way I know of.
- (void) detectSwipe {
if (touchDownLocation.y >= (touchUpLocation.y - 50) && touchDownLocation.y <= (touchUpLocation.y + 50)) {
if (touchUpLocation.x > (25 + touchDownLocation.x)) {
NSLog(@"swipe right");
}
else if (touchUpLocation.x < (25 + touchDownLocation.x)) {
NSLog(@"Swipe left");
}
}
}
@end
I think that the op must have found some other way to do this.