Quote:
Originally Posted by orange gold
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?