Reputation: 443
I have a UIView and i have added both UILongGestureRecognizer and UIPanGestureRecognizer on the view. When i tap and hold it for some seconds i get callback for LongPress recognized.
Code is as shown below
- (void)addPanGsetureForView:(UIView *)object
{
UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognised:)];
[object addGestureRecognizer:panGesture];
[panGesture release];
}
- (void)addLongPressGsetureForView:(UIView *)object
{
UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(imageLongPressed:)];
[longPress setMinimumPressDuration:1.0];
[object addGestureRecognizer:longPress];
[longPress release];
}
So i want to move the view using Pan gesture. So when the long press is recognized without removing my finger on the view i want the pan gesture to get recognized. If i remove my finger and tap and pan it again it gets recognized.
So please do help me this issue.
Thanks in advance
Upvotes: 0
Views: 237
Reputation: 4909
Taken from Apple's documentation on Gesture Recognizers
Permitting Simultaneous Gesture Recognition
By default, no two gesture recognizers can attempt to recognize their gestures simultaneously. But you can change this behavior by implementing gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
, an optional method of the UIGestureRecognizerDelegate
protocol. This method is called when the recognition of the receiving gesture recognizer would block the operation of the specified gesture recognizer, or vice versa. Return YES to allow both gesture recognizers to recognize their gestures simultaneously.
Just tested this and I think it will resolve your issue!
Upvotes: 4