I have two subviews view1 and view2. I have added LongPress and Pan gesture to my parentview.
When I longPress on view1, I will present a draggableview with popup animation just below the fingure and will continue dragging dragView to view2.
In this process panGesture selector is not called but Longpress gesture selector is called.
After i remove the fingure from dragview and then start dragging again then the panGesture selector is called.
What I need is, once the dragview is created, disable(not permanently but until pan gesture state ended is called) the longpress gesture and the pan gesture selector should be called
You have a delegate method called:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
Take a look at it, you need to return YES.
Related
I have added UIPanGestureRecognizer on the view of my UIViewController.
In this view (a calculator) are some UIButton triggered by the event .TouchUpInside.
The problem comes if I tap on the button and make a small pan at the same time (which might happen if you tap quickly a button and are moving to the next one at the same time). Then the pan gesture is triggered. I would like to avoid it when there is a tap on a button. But I would like to allow it if the tap takes too long (let say 0.3s is enough to trigger the pan gesture).
How can I achieve that?
Set the property cancelsTouchesInView of your gesture recognizer to NO.
Then your button should work properly.
You can use the delegate method like this-
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[UIButton class]]) {
return NO;
}
return YES;
}
There is a dirty solution. You can just grab it in a UIScrollView
I'm having trouble adding a long press gesture to my UITableView. Well, technically, I do have a long press gesture recognizer, but I set the minimum taps duration to 0.08. I did this because I want to have the same general action for tapping and holding down a cell, but the action only changes based on how long the cell was held. Anyway, here is the code where I add the gesture recognizer (in viewDidLoad) :
var longPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handleLongPress:")
longPress.minimumPressDuration = 0.08
longPress.delegate = self
longPress.cancelsTouchesInView = false
self.tableView.addGestureRecognizer(longPress)
self.tableView.panGestureRecognizer.requireGestureRecognizerToFail(longPress)
In my handleLongPress() function, I get the CGPoint where there was a long press and then get the tableView cell from that.
So basically, if I scroll quickly, (like if I flick the screen), the table view scrolls fine. If I try to scroll slowly, the long press event fires and I can't scroll.
All I want to do is to be able to scroll slowly, I want the tableviews default scroll gesture to override any long press.
Thanks!
ScrollViews have a panGestureRecognizer property, you can call requireGestureRecognizerToFail on your long press recognizer with the scrollView's panGestureRecognizer as an argument and it will only fire if the pan gesture in the scroll view fails.
This category might solve your problem:
#interface UITableView (CellSwipeAdditions)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
#end
#implementation UITableView (CellSwipeAdditions)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
#end
I setup a UITapGestureRecognizer on a UIScrollView in the storyboard. The Scroll View contains other contents (two UIView, one UIWebView).
The Gesture Recognizer properties are as follows:
Action: dismissPopover
delegate: postViewController
gestureRecognizers: Scroll View
state: enabled
numberOfTapsRequired: 1
numberOfTouchesRequired: 1
cancelTouchesInView: YES
delayTouchesBegan: NO
delayTouchesEnded: YES
The Scroll View (relevant) properties are as follows:
userInteractionEnabled: YES
canCancelContentTouches: YES
However, when I tap anywhere on the Scroll View, the gesture does not work.
The delegate class (conforming to UIGestureRecognizerDelegate) must implement
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
This way, the tap gesture will work.
The scroll view has it's own gesture recognizer.
You'll need to override that gesture recognizer or disable that first.
Then and then only, your gesture recognizer will work.
The better way to do this is to use the tap gesture inside the scroll view rather than adding your gesture recognizer.
I have a UIButton in a UIView that contains UIPanGestureRecognizer.
The problem is that if I hover the UIButton it steals the touch events and the pan gesture never fires.
What I want is the tap gesture recognizer on UIButton to be recognized simultaneously with the pan gesture of it's superview.
Ideas?
I've tried enumerating the UIButton gestureRecognizers property and setting each gesture recognizer the delegate to self and then using the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: delegate method returning YES but it didn't worked out.
I encountered this problem and was able to resolve it as described.
Gesture recognizer and button actions
But when I added a second UIGestureRecognizer to the same UIView the UIButton selector is not called for the second UIGestureRecognizer, only the first.
So I have a single UIView with two UIGestureRecognizers. There is a UIButton on the UIView.
The UIButton selector always get called correctly after the first UIGestureRecognizer. The first touch on the UIButton for the second UIGestureRecognizer does nothing, but the second touch on the UIButton works as expected.
If I remove the first UIGestureRecognizer from the view then the first UIButton press fires the selector as expected after the second gesture is performed.
Any idea why the first touch on the UIButton doesn't fire the selector but the second does?
try to put his delegate method in your viewController
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
returning YES to this method is guaranteed to allow simultaneous recognition.