Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-07-2009, 06:44 PM   #1 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Question Detecting Swipes is Unreliable - Help Please

I am trying to detect a two finger vertical swipe, and then take an action. Specifically I want to fade an image in, or out, depending on its current state. I can get it to work, but it is very unreliable. Sometimes it will work a few times in a row. Other times I might swipe 10 times before it works, even though I'm making the same motion (length, speed, area on screen).

User Interaction and Multiple Touch are both enable for the items in Interface Builder. My related controller.h code
Code:
// swipes
#define kMinimumGestureLength	25
#define kMaximumVariance		5

typedef enum  {
	kNoSwipe = 0
	,kHorizontalSwipe 
	,kVerticalSwipe
} SwipeType;

@interface LifeForceViewController : UIViewController <UIAccelerometerDelegate, UIActionSheetDelegate> {
	//swipes
	CGPoint	gestureStartPoint;
}

//swipes
@property CGPoint gestureStartPoint;
my related controller.m code
Code:
//swipes
@synthesize gestureStartPoint;
// swipes
#pragma mark -
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	gestureStartPoint = [touch locationInView:self.view];
}

// swipes
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
		CGPoint currentPosition = [touch locationInView:self.view];
		CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
		CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
/* commented out because detecting vertical swipe only
	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
			// handle horizontal swipe
		
	}	
	else  */
	if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
		// handle vertical swipe
	 if ([touches count] == 2)
		{
			if (imageView.alpha == 0)
// method to fade in image
				[self imageIn];
		}
	 else
		{	
// method to fade out image
			[self imageOut];
		} 
	}
}

I have been through the forum, and the source code from the Beginning iPhone Development Book, but am not finding a way to resolve this. Any insight is appreciated.

PS-I had a touchesEnded event that is used to switch from my info view back to the main screen. I thought maybe it was interfering, but commented it out and no change.
DenVog is offline   Reply With Quote
Reply

Bookmarks

Tags
multi touch, swipe, swipes, touch

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:34 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0