Basically I have a scrollView, on which there is another view.
On that view I also have a UITapGestureRecognizer.
I'm animating scrolling of the scrollView. However, during this scrolling animation, tap gesture recognizer doesn't actually recognize taps.
Any ideas?
Without code We can't give suggestion but try with below code might be useful for you!
tapGestureRecognizer.numberOfTapsRequired = 1
tapGestureRecognizer.isEnabled = true
tapGestureRecognizer.cancelsTouchesInView = false
For best practise, you can use button action instead of UITapGesture by adding UIButton. the reason is simple, to manage the button is far much simple then the UITapGesture but I am not saying use UIButton instead of tap gesture all the time, its all about your requirement.
For your case, add this line
view.userInteractionEnabled = false
and make sure your view is added in the UITapGestureand UITapGesture method is properly implemented in your code work.
For more basic, go with these two tutorials,
First tutorial |
Second tutorial
If you still face any problem then let me know.
Related
I want to block the tap gesture (perfectly just the left border one, but both will be also fine, I will just add button for it) which is responded for changing pages in UIPageViewController.
I already tried this solution in 'viewDidLoad' method:
for recognizer in gestureRecognizers {
if recognizer is UITapGestureRecognizer {
recognizer.isEnabled = false
}
}
But it worked only for the case when TransitionStyle is set for Page Curl, in my case I need to use Scroll TransitionStyle.
Ps. I also found a comment in UIPageViewController implementation that gestureRecognizers are populated only if transition style is UIPageViewControllerTransitionStylePageCurl so there will be needed some bigger "hack", hope you can help me with it.
Pps. Yes I found this - UIPageViewController returns no Gesture Recognizers in iOS 6 . solution but it's pretty old and in objC and I would be glad to use Swift here.
Ppps. Setting dataSource on nil won't work - I need swipe gesture.
You need to implement the UIGestureDelegate and then to declane gesture when such are detected.
I think here you can see good example how to do it
I have a use case where I'm adding a UITapGestureRecogniser to a UITableViewCell subclass which already has existing behaviour for navigating to another screen when tapped. The issue is that the tap seems to be 'captured' by the recogniser and then not sent on afterwards - the code in my custom recogniser is called, but tapping the cell no longer navigates to a different screen. Preliminary research suggests that if a recogniser handles a gesture then it isn't sent any further along - is it possible to change this? I have researched the responder chain but to no avail.
Cheers
For the benefit of anyone else who might happen upon this same issue in the future, I have solved my problem using this answer. All I needed to do was the following:
let recogniser = UITapGestureRecognizer(target: self, action: #selector(clickHandler))
recogniser.cancelsTouchesInView = false
I guys,
today I've updated my iPhone to iOS 9 and now have problems with a gesture recognizer.
This is the error:
WARNING: A Gesture recognizer (; target=
<(action=onVideoTap:, target=)>>)
was setup in a storyboard/xib to be added to more than one view
(->; layer = >) at a time, this was never allowed, and is now enforced.
Beginning with iOS 9.0 it will be put in the first view it is loaded
into.
I didn't have this problem with iOS8.
The view contains a UIImageView and a TextView. The recognizer was dropped into the ImageView and has only referncing outlets to this view.
I don't really understand this issue.
Can somebody help me? Thank you :)
This was happening with me because I wanted to use a Tap Gesture Recognize with an image in a TableViewCell contained in a TableView.
The problem is that:
I add one Tap Gesture Recognizer but I have more than one TableViewCell (more than one image) in my table.
iOS will assign the UITapGestureRecognizer to the first image in the first cell, and other cells will be without gestures (the gesture already set to the first image only).
To Solve this problem follow this:
Make sure you checked User Interaction Enabled for the UIView you want to assign with a TapRecognizerGesture.
in the sub-view TableViewCell in my case add a new UITapGestureRecognizer. The code:
internal let tapRecognizer1: UITapGestureRecognizer = UITapGestureRecognizer()`
In your main view TableView in my case and for every cell assign the UITapGestureRecognizer you made with each cell to a main function in the main view:
cell.tapRecognizer1.addTarget(self, action: "img_Click:")
cell.img.gestureRecognizers = []
cell.img.gestureRecognizers!.append(cell.tapRecognizer1)
Add the function you want UITapGestureRecognizer to fire when clicked:
func img_Click(sender: UITapGestureRecognizer) {
print("ok")
}
Notes:
You can use simple way if you do not want the UITapGestureRecognizer action in the main view by assigning it in its sub-view directly.
in step 4 function name must be the same as in addTarget line.
I think that this problem happen when you use storyboard added a Tap Gesture Recognizer. Because some reasons you added more than one views.(see the picture).
So, delete other wrong views,leave the right one view.
Already fixed it.
The storyboard is localized and in one language I assigned the the recognizer twice to the picture view.
Somehow this seemed to cause troubles on the other storyboards too.
I am using the standard UITableView editingMode to move Cells via Drag & Drop. Works like a charm, perfectly integrated to my Core Data Model and everything.
However, usability-wise I dislike that the user has to long-press the Editing Accessory (|||). I would like to change the minimum duration of the UILongPressGestureRecognizer to something like 0.1f.
The trouble: I cant seem to access the right Gesture Recognizer. UITableViewCell's gestureRecognizers-array is empty, the UITableView's gestureRecognizers array contains only private recognizers:
UIScrollViewDelayedTouchesBeganGestureRecognizer
UIScrollViewPanGestureRecognizer
UISwipeGestureRecognizer
UIGobblerGestureRecognizer
I looked at several github-Projects:
https://github.com/bvogelzang/BVReorderTableView
https://github.com/FlorianMielke/FMMoveTableView https://github.com/mystcolor/JTGestureBasedTableViewDemo https://github.com/shusta/ReorderingTableViewController
They all focus on re-engineering UITableView so you dont have to access the built in editing mode - and instead can long press any UITableViewCell anywhere WITHOUT entering editing mode.
As I simply want to change the minimumPressDuration of the built in editing mode (and am actually fine with restricting the "access point" for the drag gesture to the Accessory View) I am reluctant to use these custom implementations potentially prone to errors and trouble.
Looking forward to your help! Thank you!!
Cheers,
Chris
You may want to access the UITableViewReorderControl, as discussed in this article, and then look for any attached gesture recognizers. If you find any, you should then be able to change the minimumPressDuration property.
Swift 5
You can change the minimumPressDuration to 0. So that you can enter drag and drop mode without a long press.
let gesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
gesture.minimumPressDuration = 0
I have a textView to input some text or emotion. so I make another button to change the keyboard to custom emotion view, and I also use tap GestureRecognizer for when I want to change back to keyboard.
I found every time I need to touch the button twice, the tap GestureRecognizer can work well. I thought and search long time but no result, finally I fix it. I think some one will meet the same question, so I shared it below.
because my add tap gesture recognition 's code is in init code, but when I tap textview, keyboard was pop up, the textview's position was changed too, so the init tap gesture recognition code isn't work now.
I fix it with add tap gesture recognition delay 0.3 s.