Reputation: 7383
As I have CustomView
where i want to detect Touch Event
like when user do Touch
Down/Up and release or visa versa as in this Image.
What I tried
Swipe But in Which i Get only coordinate where user releasing the finger. like tap on X = 100
and releasing on 10
and m getting 10
only.
What i am looking for
Want to get whole coordinate like user tap on X = 100
and release on X = 80
then looking for on every single coordinate changed like 100,99,98,97,96,95,94.......80.
equally as finger moving.
Please if anyone have any idea about it or something i forget to do. Please Review.
Upvotes: 0
Views: 570
Reputation: 6427
Change this to your .h file
@interface ViewController : UIViewController{
CGFloat touchStartPoint;
CGFloat touchOffsetPoint;
CGFloat tempTouchOffsetPoint;
}
@end
And this to your .m file
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
touchStartPoint=[touch locationInView:self.view].y;
touchOffsetPoint = 0;
tempTouchOffsetPoint = 0;
// NSLog(@"touchStartPoint = %f",touchStartPoint);
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
touchOffsetPoint = [touch locationInView:self.view].y - touchStartPoint;
if (touchOffsetPoint>tempTouchOffsetPoint) {
NSLog(@"touch down");
}else{
NSLog(@"touch up");
}
tempTouchOffsetPoint = touchOffsetPoint;
}
Upvotes: 1
Reputation: 6529
Here is how I have done it:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp|UISwipeGestureRecognizerDirectionDown;
[self.gestureAreaView addGestureRecognizer:swipeGesture];
[swipeGesture release];
-(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender
{
//Gesture detect - swipe up/down , can't be recognized direction
}
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeGesture];
[swipeGesture release];
UISwipeGestureRecognizer *swipeGesture2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture2.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture2];
[swipeGesture2 release];
-(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender
{
//Gesture detect - swipe up/down , can be recognized direction
if(sender.direction == UISwipeGestureRecognizerDirectionUp)
{
}
else if(sender.direction == UISwipeGestureRecognizerDirectionDown)
{
}
}
Hope this helps out
Upvotes: 1
Reputation: 2052
Try this method
// declared somewhere
@property (nonatomic, retain) NSMutableArray *touchPositions;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [[event allTouches] anyObject];
CGPoint loc = [touch locationInView:self];
[self.touchPositions addObject:[NSValue valueWithCGPoint:loc]];
}
Upvotes: 0