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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 10-06-2008, 05:14 PM   #1 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default touches moved - help me

ok so basically i have a lighter and i want to be able to set the touches moved code so i can make a touch area so when i touch and slide my finger i can add the code to make the flame go out

i was thinking something along the lines of....
Code:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [[event allTouches] (60.0, 85.0, 300.0, 800.0)];
or something like that
but anything that will work is fine also

Last edited by orange gold; 10-06-2008 at 05:54 PM.
orange gold is offline   Reply With Quote
Old 10-06-2008, 05:53 PM   #2 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

or you can add an invisible image that i can slide on to change another image i already have in place.
orange gold is offline   Reply With Quote
Old 10-06-2008, 10:54 PM   #3 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 420
jeff_lamarche is an unknown quantity at this point
Send a message via AIM to jeff_lamarche Send a message via Yahoo to jeff_lamarche
Default

Not sure what you think that code will do, but it sounds like you want to do a fairly standard swipe detection, like:

Code:
- (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);
	
	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
		// handle horizontal swipe
		
	}	
	else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
		// handle vertical swipe...
	}	
	
}
__________________
Check out my iPhone Dev Blog
You can send me e-mail at my forum username at mac dot com.
jeff_lamarche is offline   Reply With Quote
Old 10-06-2008, 10:57 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 288
Kenrik is on a distinguished road
Default

Another Lighter? or is this one of the ones that's already in the store?

just curious.
Kenrik is offline   Reply With Quote
Old 10-07-2008, 05:37 AM   #5 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

with your code i put it in and get 5 variables, do i have to add some other code somewhere else first? maybe an include file code? if you could post a download link to an example project using it that would be great, hanks - og
orange gold is offline   Reply With Quote
Old 10-07-2008, 09:23 AM   #6 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 420
jeff_lamarche is an unknown quantity at this point
Send a message via AIM to jeff_lamarche Send a message via Yahoo to jeff_lamarche
Default

Quote:
Originally Posted by orange gold View Post
with your code i put it in and get 5 variables, do i have to add some other code somewhere else first? maybe an include file code? if you could post a download link to an example project using it that would be great, hanks - og
no can do, I took this code from a non-public project. Let me take a step back and do a little more handholding version. In your controller class' header file, you're going to need to declare an instance variable to hold the starting point:

Code:
CGPoint		gestureStartPoint;
You should also define two constants which will define just how much of a swipe is necessary, and how straight it must be:

Code:
#define kMinimumGestureLength	25
#define kMaximumVariance		5
You can tweak these two values to suit your needs.

Then, in your controller class, implement touchesBegan:withEvent: and store off the starting point of the gesture

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	
	UITouch *touch = [touches anyObject];
	gestureStartPoint = [touch locationInView:self.view];
	
}
and then, finally, detect the swipe in your touchesEnded:withEvent: method:

Code:
- (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);
	
	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
		// handle horizontal swipe
		
	}	
	else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
		// handle vertical swipe...
	}	
	
}
Make more sense?
__________________
Check out my iPhone Dev Blog
You can send me e-mail at my forum username at mac dot com.
jeff_lamarche is offline   Reply With Quote
Old 10-07-2008, 07:24 PM   #7 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

THANK YOU!!! YOU ROCK! now my app is finalized and ready for selling xD
orange gold is offline   Reply With Quote
Old 03-19-2009, 02:35 AM   #8 (permalink)
Registered Member
 
brendand's Avatar
 
Join Date: Aug 2008
Posts: 223
brendand is on a distinguished road
Default

I'm having a small problem with this code on my view that has a UITableView. When I swipe left, the swipe is detected fine. But when I swipe right, no swipe is detected. I've add the above code to my controller class.

I've also put a breakpoint in touchesBegan, but it doesn't stop on it at all for swipes to the right.

Any ideas?


Thanks,
brendand is offline   Reply With Quote
Old 03-20-2009, 04:29 PM   #9 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

ok its been a while scence ive used this...

things to try:
take out the break point... does it work?
change the amount to -25 instead of 25 ?? now is it detecting right?
change the > sign to a < sign... if that switches the detection to right instead of left the use the > and after that put a || and then a < (incase you didnt know.. but im sure you do.. in an if statement.. adding || is the same as adding "or, ... " in english

GOOD LUCK
orange gold is offline   Reply With Quote
Old 03-20-2009, 08:12 PM   #10 (permalink)
Registered Member
 
brendand's Avatar
 
Join Date: Aug 2008
Posts: 223
brendand is on a distinguished road
Default

Well, it still doesn't work when I take out the breakpoint. That's why I put the breakpoint there in the first place. I wanted to see if the code was being executed at all on a right swipe. I think the issue stems from the fact that normally a right swipe brings up the delete button when you implement tableView:commitEditingStyle:forRowAtIndexPath. But in this case I'm not implementing that method. I may have to implement touchesMoved on a subclass of UITableView. Not sure just yet.

I thought your statement below was funny when you were explaining what "||" means as I read it already as "or" in my head.

Thanks,

Quote:
Originally Posted by orange gold View Post
ok its been a while scence ive used this...

things to try:
take out the break point... does it work?
change the amount to -25 instead of 25 ?? now is it detecting right?
change the > sign to a < sign... if that switches the detection to right instead of left the use the > and after that put a || and then a < (incase you didnt know.. but im sure you do.. in an if statement.. adding || is the same as adding "or, ... " in english

GOOD LUCK
brendand is offline   Reply With Quote
Reply

Bookmarks

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
» Online Users: 309
11 members and 298 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, jbro, n00b, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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