UITapGestureRecognizer issue in iOS 9 - ios

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.

Related

How to block tap gesture on UIPageViewController with Scroll TransitionStyle

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

Conflict with a UIPanGestureRecognizer on a UITableView's superview

I'm trying to build something roughly similar to the drawer menu in Apple Maps on iOS.
In this Xcode project I'm attaching a UIPanGestureRecognizer on the VC's view, and as the panning happens, move vertically a UITableView with scrolling disabled.
The issue is every time after the pan ends, the didSelectRow method is called only after a second tap happens somewhere on the UITableView. Of course I'd like it to be called after the first tap.
The funny thing is that the bug does not happen if I enable the table's scrolling, and in the gesture recognizer's delegate have shouldRecognizeSimultaneouslyWith returning true.
Other funny thing is a very similar thing seems to happen in Apple Maps itself, if you try pulling the drawer up with the finger resting on a recent location entry from the list inside the drawer.
Thanks for your help!
I don’t understand well what are your saying.
But I think that the main problem is with “Chain Responder”. When you use PanGestureRecognizerand the UITableView property isScrollEnable = false in the Responder Chain the PanGestureRecognizer it is the first who is called, and the system wait to that fails or the event is not handled, then it is passed to the next in the Responder Chain, who is the UITableView. For that reason, it takes too long to get called the didSelectRow function
I suggest to you create a new UIView and insert in the ViewController in the storyboard o nib and put the UITableVIew outside of that UIView, then link the PanGestureRecognizer to that new UIView. In that way the Responder Chain don’t get in conflict with both, because the system can detect when the drag is in the new UIView and call only to the PanGestureRecognizer and when it is in the UITableView will call to the didSelectRow
Best Regards
Write if it does not resolve

UITapGestureRecognizer doesn't tap while UIScrollView is scrolling

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.

Touch Down firing in a weird way

I'm adding a touch down action to a uitextfield (actually it's a subclass, but I think that might not be important). I created a simple view controller and added this textbox to it, and wired up the event to println("Hello").
When I quickly tap the item (both in simulator, and on my phone) it works perfectly and says hello!
I then created a UITableViewController subclass, and in one of the static cells I added the same textbox.
In this case, when I quickly tap the textbox nothing happens! When I actually hold down the mouse or my finger for about 1/2 a second, it works. But not if I quickly tap it.
This is different from the previous textbox, which always works perfectly no matter how fast I tap it.
Are there some problems with different events being intercepted ors something of that sort?
I even went so far as to add a tap gesture recognizer to both the table cell, and the textbox, but neither work unless I hold it down (the table cell action won't even fire unless I click off the textbox and into the cell proper, of course).
Thanks so much this is very strange.
UIButton not showing highlight on tap in iOS7
and
iOS - Delayed "Touch Down" event for UIButton in UITableViewCell
have a lot of information about this. Apparently there is a delay for uitableviewcells that can be avoided by taking some of the approaches above.
I'll post the solution that works for me once I work on it. thanks!
EDIT OP DID DELIVER!! (lol sorry)
in IOS8, the idea is that table cells no longer have the uiscrollview that would basically delay the touching, so what you can do instead is something like this in your page did load:
for subview in self.tableView.subviews as [UIView]
{
if subview is UIScrollView
{
let scroll = subview as UIScrollView
scroll.delaysContentTouches = false
break
}
}
So see how we're iterating over self.tableview's subviews, and anytime we hit a scrollview set delaysContentTouches to false. This worked for me on both the simulator and on my phone.

UITableView - move cell - How to enter dragging mode without long press?

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

Resources