UICollectionView didselect and double tap conflict - ios

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.

Related

UITableView cancels UITapGesture

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.

Single tap gesture to multiple View using storyboard

How to have single tap gesture to multiple Views using storyboard.
I drag 3 views and one tap gesture into UIView class.
Contacted three view to tap gesture and added action class handleGesture Method on tap on any one the tree view it should trigger the method action.
using story board.
But i want to do it with single tap gesture is it possible or not.
try with this, define a variable UITapGestureRecognizer with your method, after that, in a method or wherever you want, you can add this gesture to your multiple views
var recognizerMovements: UITapGestureRecognizer {
get { UITapGestureRecognizer(target: self, action: #selector(self.myActionMethod)) }
}
self.myFirstView.addGestureRecognizer(myActionMethod)
self.mySecondView.addGestureRecognizer(myActionMethod)

iOS: How to write handler for Tap Gesture Recognizer if dragged in from storyboard?

I have an image and in the storyboard I've dragged a Tap Gesture Recognizer on top of this image and changed the settings:
For my TGR:
For my image:
How do I hook this up to my controller now? I want a method to fire off when the double tap happens. Is there some sort of protocol I have to conform to? Do people normally do this from the storyboard or programmatically in viewDidLoad? I don't mind doing it another way if that's the general trend of things.
connect the gesture recognizer as a outlet to your ViewController and in your viewDidLoad :
[self.yourGesture addTarget:self action:#selector(didTapOnImage:)] ;
and then declare your method didTapOnImage method :
-(void)didTapOnImage:(UIGestureRecognizer*) recognizer
{
//do your work here
}

Recognize swipe gesture in view not in subview

I have added a subview to a View Controller's view. This subview is the view of QLPreviewController.
What I am trying to achieve is to recognize swipe gestures on the subview in the parent view, i.e. the View Controller's view. In the end, I want to be able to swipe left /right on the view to load the next document for preview.
I'm aware of hit testing and understand that by just attaching a gesture recognizer to the parent view, those will not be recognized, since the subview will be the "hit-test" view.
Now what is the best (or easiest) way to recognize those gestures?
Note: I didn't manage to attach the gesture recognizers to the subview, this doesn't seem to work.
* UPDATE *
To make this more clear - this is the code from my ViewController. vContent is just a view in my ViewController, where I add the view of the QLPreviewController:
let pvVc = QLPreviewController()
pvVc.dataSource = self
vContent.addSubview(pvVc.view)
I tried adding the swipe recognizers both to the vContent and the pvVc.view. In both cases no event was fired.
let sgrLeft: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action:Selector("handleSwipe:"))
sgrLeft.direction = UISwipeGestureRecognizerDirection.Left
sgrLeft.delegate = self
On some other view the code works fine.
Any hint is appreciated!
Thx
Eau
Well, the responder chain, the unknown animal … ;-)
You can subclass the superview and override -hitTest:forEvent:.
You rarely need to call this method yourself, but you might override it to hide touch events from subviews.
Gesture Recognizers Get the First Opportunity to Recognize a Touch, so even the subview is hitTest view. the gestureRecognizer attached on superView can recognizer touch event.

Swift UIScrollview double tap uitbutton zoom

I have a view hierarchy like this:
UIView -> UIScrollView -> UIView (contentView) -> UIButton
I have added code to the UIScrollView to activate zoom when the user double tap.
This is working well, the content view and the UIButton are zooming.
In my content view, I have some UIButton, my problem is when I double click on this button, I want the scroll view to zoom (this is ok) but I don't want my button to fire the event (this is not ok)
I want the button to only fire an event if the user click on it one time, but not with double tap.
In my case, the UIButton can be small, and I want the user to get the possibility to double tap on it to zoom, but to fire an action only if it is a one click.
I try to do this with swift
thanks a lot for your help
Instead of UIButton, use UIView or UIImageView as button and add UITapGestureRecognizer to it.
And implement the following logic:
if the view is double tapped {
call your zoom function
}
if the view receives single tap {
then perform your button click function
}
Hope it helps :)

Resources