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

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

Related

ios voiceover slider double tap and hold, but for custom view

I've created a custom view that acts like a UISlider - there is a "track", and a handle to "grab" to change the value. For particular reasons, I can't just make it a subclass of UISlider. I'm trying to make this slider as accessible as possible with VoiceOver. I have accessibilityIncrease and accessibilityDecrease on my custom view that handle single finger drag up and single finger drag down. This changes the value of the slider by 10% at a time.
However, I'd like to allow more fine grained control, just like a non-VoiceOver slider. By default , UISlider has double tap and hold, and you can drag up/down to "pan" the slider. I'd like to add exactly that to my custom view, but I can't find the correct incantation to handle the double tap and hold gesture.
Is there something I can do to mimic the double tap and hold gesture from UISlider on my custom view?
Thanks very much!!!
If you want to implement this kind of new gesture for VoiceOver users, just forget it.
The recommended gesture for this kind of UI control is definitely the implementation of adjustable value as you already did apparently.
I don't think it's a good idea to try and implement new VoiceOver gestures in an application because its users have their habits and they may be totally lost with your customed control if they cannot handle it unless you add an hint to explain but that's definitely not what I recommend anyway.
Otherwise, you could take a look at the pass through concept introduced in the What's New in Accessibility WWDC 2017 video that deals with the same idea but for a panning gesture...

How to add long press functionality to a UITextField

I added a UILongPressGestureRecognizer to a UITextField only to find that the only thing that got triggered was the UITextField's magnifying glass; and then when the magnifying glass disappeared the context menu appeared.
What do I have to do in order for my UILongPressGestureRecognizer to be triggered instead of the default behavior?
I've already tried disabling all UILongPressGestureRecognizers before adding my own, as per some other SO answers, but to no avail.
Put a UIView on top of the textField with the same frame. Make it clear background. Add your gestures to your UIView and handle custom selections from there on. Make a tap gesture to start editing the text manually. And make a longpressgesture to do whatever you want. etc.

UITapGestureRecognizer issue in iOS 9

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.

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.

why does GestureRecognizer not work on textview first time?

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.

Resources