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.
Related
I have a view (I'll call it parentView) that has about 20-30 subviews. I have added a long press gesture recognizer to the parentView. The gesture recognizer only seems to fire when I press on the parentView, it does not fire when I press and hold on one of the subviews.
I have tried adding the gesture recognizer to self.view and using the gesture location to see if it was within the bounds of the parentView. However the same problem occurs since it does not seem to detect my long press on the subviews.I have also tried running a for loop and adding the gesture recognizer to each individual subview but this also did not work.
This is how I am defining my gesture recognizer if anybody was wondering.
longPress.minimumPressDuration = 1
longPress.addTarget(self, action: #selector(ViewController.handleLongPress)
parentView.addGestureRecognizer(longPress)
How would I get the long press gesture recognizer to detect a long press on the parentView and it's subviews?
First of all, I have open the image's User Interaction Enabled.
But why I can't drag the gesture ?
The gestureRecognizers in Outlet Collections is a outlet to the gesture recognizers of that view, not an action of its gesture recognizers.
What you need to do is adding a gesture recognizer to the image view by dragging one from the Object Library and adding its action
You can drag the gesture like this:
Drag a TapGesture Recognizer to the ViewController in storyboard:
You should write a IBAction method in the ViewController.m:
```
-(IBAction)tapGesture:(id)sender {
}
```
Drag the TapGesture Recognizer to ViewController, then choose the delegate and the tapGesture: method:
Then you can drag the imageView's gestureRecognizers to the gesture:
The function you write in ViewController.m is what you want.
I've a view controller with UISegmentedControl and UITableView as its children. In -viewDidLoad I create a UITapGestureRecognizer and add it to the controller's main view.
When I tap on, for instance, a cell of the table view, the tap gesture recognizer's action is being called and it prevents receiving touches to the table view (that's ok as tapRecognizer.cancelsTouchesInView == YES).
However, the issue is that when I tap on the segmented control, the tap gesture recognizer's action is not being called. Why is it so? How to make the tap gesture recognizer the "top" object which handles touches?
Thanks,
Adam
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.
I am overriding my horizontal image UIScrollView with a panning gesture recognizer to detect a user swipe.
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panGestureCaptured)];
[imgHorizontalScrollView addGestureRecognizer:panGesture];
My question is: Is there a way for me to reset imgHorizontalScrollView's pan gesture recognizer back to default in the panGestureCaptured method? The reason I ask is because since I am overriding this gesture, once the user swipes and the gesture is picked up, I am no longer able to scroll in the scroll view. I also tried to remove the gesture but that also prevents me from being able to scroll.
try UIGestureRecognizerDelegate gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: with scrollView's gestureRecognizer got by panGestureRecognizer
Try setting
panGesture.cancelsTouchesInView = NO;
If that doesn't work, you should find a way to change your gesture handler to the scrollViewDidScroll: delegate method