2D Toolkit Forum

2D Toolkit => Support => Topic started by: zblack on March 15, 2015, 08:32:53 pm

Title: tk2dUIScrollableArea sometimes "sticks" on devices (iOS/Android) when swiping
Post by: zblack on March 15, 2015, 08:32:53 pm
Heading says it all: When trying to swipe/flick to scroll, the content will just dead-stop the instant you release your finger. Happens anywhere between 10-20% of the time depending on the device. Has anyone else encountered this and found a fix?

(Previously, when I coded my own scrolling area for iOS in Xcode using C++, I ran into this problem as right away, and had to do some trickery to prevent it from happening. I was surprised to see that it had not been addressed in tk2d.)
Title: Re: tk2dUIScrollableArea sometimes "sticks" on devices (iOS/Android) when swiping
Post by: unikronsoftware on March 17, 2015, 02:05:12 pm
I've not seen that happen on iOS at all - we test on iOS a lot more than Android. Its impossible to guess what the cause is without seeing and debugging it. If you do find a reliable way to reproduce this post the device & instructions and I'll investigate if I can get my hands on the same device.

Edit - only thing I can think of is that its registering another touch down & up immediately after letting the first one go, like a bounce.
Title: Re: tk2dUIScrollableArea sometimes "sticks" on devices (iOS/Android) when swiping
Post by: zblack on March 20, 2015, 02:48:28 am
The problem is the line "swipeCurrVelocity = ... " in UpdateSwipeScrollDestintationPosition() of tk2dUIScrollableArea.cs. What happens is that the value can be set to 0 if the user happens to release their finger on the frame that a swipe delta had just begun to calculate (i.e., the start point and end point are equal). The "quick fix" is to merely check if the two value are equal, and if so, don't re-calculate swipeCurrVelocity. It will be left with it's previous delta value and you'll get good velocity on all releases. I tried a couple of other techniques, including weighting and averaging the two values together, but inevitably you get "sticky" swipes at 1/2 speeds and such. Ideally, the algorithm should be keeping a running weighted average of the last several swipe deltas over time, and use that averaged value to set swipeCurrVelocity on release.
Title: Re: tk2dUIScrollableArea sometimes "sticks" on devices (iOS/Android) when swiping
Post by: unikronsoftware on March 21, 2015, 11:35:22 pm
Cheers for that. This is all very familiar, I can't quite place it, almost like some kind of I've fixed this before deja-vu. I'll have a poke around the old source repos in case it was something that was never checked in...
Title: Re: tk2dUIScrollableArea sometimes "sticks" on devices (iOS/Android) when swiping
Post by: zblack on March 28, 2015, 03:17:07 pm
So I realized a problem with my "fix": If you *intend* to release the scroll area without moving it (points are equal), it still moves! Yergh. So really the only way to properly fix this is an average of the last several deltas, so if you hold in place for a second and then release they will all be zero.