How to detect swipe direction?
scott at tactilemedia.com
Sun Oct 6 19:26:39 EDT 2013
Might be wrong, but I don't believe there's a built-in swipe
monitor/property. I put together the following to detect course swipe
direction and added the ability to track the swipe angle. You can set the
swipe distance threshold to control when an event is triggered from a
swipe. The code is written to place direction output in a field.
-- 50 PIXEL SWIPE THRESHOLD
local hStart, vStart, theSwipeData
local theThreshold = 50
on touchStart theID
put item 1 of mouseLoc() into hStart
put item 2 of mouseLoc() into vStart
on touchmove theID, X, Y
put empty into theSwipeData
if Y > vStart and abs(vStart - Y) > theThreshold then put "down,"
if Y < vStart and abs(vStart - Y) > theThreshold then put "up," after
if X > hStart and abs(hStart - X) > theThreshold then put "right,"
if X < hStart and abs(hStart - X) > theThreshold then put "left,"
if theSwipeData is not empty then put locToAngle(X,Y,hStart,vStart)
on touchEnd theID
put "swipe: " into theResult
if theSwipeData is not empty then put theSwipeData after theResult
set text of fld 1 to theResult
function locToAngle pX,pY,pXorigin,pYorigin
put atan2(pY - pYorigin,pXorigin - pX) into R
Hope this helps.
Tactile Media, UX/UI Design
On 10/6/13 2:09 PM, "Roger Eller" <roger.e.eller at sealedair.com> wrote:
>I want a different action to occur based on the direction the user swipes
>control. For example:
> on swipeLeft
> set the backgroundColor of me to red
> end swipeLeft
> on swipeRight
> set the backgroundColor of me to green
> end swipeRight
>Is there a one liner on mobile that can give me the direction, or
>true/false, or l/r/u/d?
>use-livecode mailing list
>use-livecode at lists.runrev.com
>Please visit this url to subscribe, unsubscribe and manage your
More information about the Use-livecode