Get notification when user pauses dragging - flutter

is there a way to get notified when user stops dragging over the screen (using GestureDetector) when the finger is still on the screen? After lifting the finger I do get DragEndDetails event. What I need is sort of "user paused scrolling". Current behaviour is: while moving the finger I do get DragUpdateDetails but when I stop dragging (finger on the screen, drag velocity is 0) neither DragUpdateDetails nor DragEndDetails are fired.
Cheers.

You could just setup a timer (e.g. 1 second) when you receive a drag update event.
If no drag update occurs during that time (or only minimal drag occurs), trigger your callback. Otherwise, if there is significant movement, restart the timer...
When the drag is cancelled or the finger is removed or the widget is disposed, cancel the timer.

Related

deactivating/activating a UGUI button leaves it in pressed state

I have a button with "animation" transition type. When I click it, I call SetActive(false) on its gameObject. Then, by clicking another button, I call SetActive(true) to activate the deactivated button, but the animation does not reset: it's still in pressed state (like it was when I deactivated it, because I was pressing it), and it does not back to idle state.
EDIT: I realized I have not set the sprite for "normal" state in the animation. But I don't understand why before deactivate/activate, the button is showing default sprite for idle state, and after deactivate/activate, is showing pressed sprite for idle state.

Disabling touchEnd when pressing buttons

I have a game which is controlled through swipe gestures.
Each turn, the user swipes and it moves pieces on the screen.
My problem is, when pressing the "Start" button, the game starts and sometimes records the first swipe gesture at the same time.
How do I disable the touch messages when I am pressing a button?
You can add a touchEnd handler to the Start button:
on touchEnd
end touchEnd
As long as you don't have a pass touchEnd command in this handler, the touchEnd handler higher up de message hierarchy won't run.
Another possibility is to check for the target higher up the message hierarchy:
on touchEnd
if the short name of the target is "Start" then
exit touchEnd
else
// remainder of your script
end if
end touchEnd

How to cancel UITapGestureRecognizer?

I noticed that the single tap happens when the touch dragging is performed quickly.
I want to cancel the single tap if the user moves the touch.
How can I do this?
I noticed that the single tap happens when the touch dragging is performed quickly.
My suggestion is to do nothing. Assuming you have everything set up properly then what you are going to end up doing is creating an app specific behavior for dragging simply to accommodate your personal preference. This could confuse your customers and possibly prevent your app from getting approved.
If the problem you are experience cannot be duplicated in other apps then I would guess that you are doing something incorrectly with respect to the responder chain, and you should focus on fixing that first.
I'm going to assume that you don't want to cancel the tap gesture itself (once the tap gesture has fired, I don't think you can cancel the gesture, it's already done!), but rather the code fired from it.
What you could do is create a timer, and delay the action created by the tap gesture by a second or two. You then have that time interval to cancel the action.

ccTouchesMoved and selector:#selector(ButtonTapped:)

Ill try and keep this as simple as possible.
I have a guy which you drag around the screen
I have a shoot button which fires bullets
To drag the guy around the screen im using ccTouchesMoved, basically get the users finger movement and set the guy to that place. Done.
I have a button which is a CCMenuItemImage and if it is tapped then is called a selector to run a method. The method simply fires some bullets. Done.
Now my problem is i cant have these two things work at the same time. I would like the player to be able to drag around the guy and shoot at the same time. Im assuming the button is not being tapped becuase the user is touching and dragging around the player.
How can i fix this? Still be able to drag around with one finger and press the shoot button with the other and they both work together?
You might want to implement your fire button using a sprite. You can handle ccTouchesBegan and ccTouchesEnded to check for a press within the bounds of your button, to swap it with a pressed state (on begin) or to implement the fire action (on end).
In your ccTouchesMoved handler, you can iterate over the set of touches and determine if the touch that moved is the one over the button, or the touch that should change the character position.

Cocoa Touch - Handling touches that get interrupted or lost

I have a couple places in my app where UI elements reset themselves when a touch ends on them. For example, hiding a dashed outline, sliding a view back to the default position.
The problem is that on occasion the app loses track of the touches. One example is if I slide the view upward and cause a UIAlertView to show, the view doesn't slide back, because the reset code is in touches ended. The touch ends during the time the UIAlertView is active, and the view doesn't reset. The same example works for hiding the dashed outlines.
My question is, where/how can I handle the reseting of these custom UI elements so that when a touch ends without being noticed it will still reset. TouchesEnded isn't always doing it for me.
Have you try touchesCancelled? I think it is called when the touch get interrupted.
EDIT: If this doesn't work then maybe you can manually add code that cancel the touch when you initiate the alert.