I am using a UISwipeGestureRecogizer
to swipe left
and right
by using UISwipeGestureRecognizerDirectionRight
and UISwipeGestureRecognizerDirectionLeft
and its working totally fine but the default swipe is too sensitive, its just a little bit more than a tap.
Is there any way by which I can make it work like when a scrollView
works when its paging enable
property is true that till the user doesnt lifts its finger up, its doesnt work.
It will be fine if the view doesn't move with the finger moving, and only work when a left
or right
gesture is performed and the finger is lifted. Thanks.
A UISwipeGestureRecognizer
will not give you any option to change the sensitivity or any other aspect of the swipe. To obtain more control over the swipe, you could use one among the following:
Here is something to try with UIPanGestureRecognizer
:
- (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer{
CGPoint velocity = [gestureRecognizer velocityInView:yourView];
if(velocity.x > 0){
//Right gesture
}else{
//Left gesture
}
}
All UIViews
inherit from UIResponder
, so you can use the touchesBegan
, touchesMoved
and touchesEnded
method for calculating the touch. Try something like this:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
start = [touch locationInView:self.view];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint end = [touch locationInView:self.view];
//Compare start and end points here.
}