UITableView cancels UITapGesture - ios

uitableviewdidselect cancel outs tap gesture action
there is an UIImageView in cell.contentView and there is a tap gesture to enlarge the image the control is not going to the Tap Gesture action its passing to the tableview didselect delegate ? I am using UITableView class for my table already did userInteractionEnabled=YES & cancelsTouchesInView = NO

Make sure you set
tapGestureRecognizer.cancelsTouchesInView = NO;

It won't work because table view can't take two user interactions at a time. First it will give priority to didSelectRowAtIndexPath. You need to disable user interaction on cells. So that tap gesture will be called. Make sure that user interaction enabled for imageView.

Related

How to get scrollView.keyboardDismissMode delegate?

I want to know when the tableView was actually dragged without adding any gesture recognizers. (I already have too many gesture recognizers)
self.tableView.keyboardDismissMode = .OnDrag
The tableview inherits from UIScrollView, so you can use the scrollview delegate UIScrollViewDelegate to see when the user starts dragging. This delegate will be set up if you have set the tableView delegate to your ViewController. The method to use is scrollViewWillBeginDragging

UICollectionView didselect and double tap conflict

There are two actions I tried to do.
Single tap which is select the cell to push to a new view controller.
Double tap to animate the cell.
I registered a double tap gesture and set doubleTapGesture.delaysTouchesBegan to ture. The single tap action is just a segue from cell to another viewcontroller.
However, there is a 0.5s delay if user single tap the cell to move to another view. The problem is the system wait for double tap gesture. If I remove the delaysTouchesBegan, it only recognize the did select cell function.
How can I reduce the delay?
Please add this line
tapgesture.delaysTouchesBegan = YES;
Assume there is a view (V) with UICollectionView (CV) inside it. Add double tap gesture to the V with settings:
doubleTap.numberOfTapsRequired = 2
doubleTap.delaysTouchesBegan = true
doubleTap.cancelsTouchesInView = true
Implement the didSelect of the CV.
It would be work separately the didSelect and the double tap. However because of delaysTouchesBegan it would be the delay before didSelect would fire.

How do I make a UILabel *not* pass touches to the UITableViewCell it's embedded in?

I have a UITableView with a bunch of cells, and I add a UILabel to each. I want the UILabel, when tapped, to accept the touches, not the cell. Obviously if they tap outside of the label and still on the cell that is fine, but if it's on the label the cell should not cause a segue or action or whatever, only the label's action on tap should fire.
My normal method to cause this is to set the UIView's userInteractionEnabled to YES, but in this case when I set it on the label it doesn't cause anything different to happen. When I watch touchesBegan in the label subclass those methods do fire, but the cell selection does as well.
How do I make the UILabel not pass the touches on to the cell?
I recommend adding a UITapGestureRecognizer to the label and setting cancelsTouchesInView property to YES to prevent the touches from being delivered to the view upon gesture recognition, ex:
UITapGestureRecognizer *labelTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
labelTapGesture.cancelsTouchesInView = YES;
[label addGestureRecognizer:labelTapGesture];
label.userInteractionEnabled = YES;
And since you don't want the gesture to perform an action, you can set its action to nil.

Tap Gesture Recognizer and UIControl

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

IBAction UIButton firing is delayed

I have a UIButton connected to an IBAction in Interface Builder.
The Problem:
The action firing and the de-highlight of the button both take a little bit to happen.
The Facts:
View structure:
View
10 Buttons (connected via UIControlEventTouchUpInside to the IBAction
View (Subview)
Gesture recognizer
Text Field
The Subview has a UITapGestureRecognizer, which delaysTouchesBegan and delaysTouchesEnded both are set to NO
The action is happening in the main thread.
Testing a simple button (with no images or title, and only a simple NSLog), the result is the same
The Question:
Why are firing and the de-highlight delayed?
In the end, I added somewhere some UIGestureRecognizer, and forgot to set delaysTouchesBegan to NO =(
Ok I think that because of the UITapGestureRecognizer .. try to do the following :
connect an IBOutlet to your button.
2.assing the UITapGestureRecognizer delegate to your ViewController.
3.Implement this gesture delegate method in yourViewController
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
return (! [yourButton pointInside:[touch locationInView:yourButton] withEvent:nil]);
}
This will make the tap to be recognized to your button not to the recognizer.
Make sure your touch event is set the first contact of the button which would be the touch down event otherwise there will be a delay in the action until whichever other event you chose gets completed (i.e. touch up inside, touch up outside, etc).
In my case, there was a delay on IBAction for a button that was in a custom CalloutView of an MKAnnotationView.
In the same way there is a ~0.5sec delay between pressing the MKAnnotationView and the MKAnnotationView actually being selected, there is also a delay between any other user interactions you might add as a subview of the MKAnnotationView.
The solution is to disable the native UIGestureRecognizer within MapView that is causing the delay of any MKAnnotation view selections.
This can be done with the solution on this post:
Set isZoomEnabled = false within a gesture recognizer attached to the mapview on any tap, then set isZoomEnabled = false within a 0.5sec async dispatch.

Resources