Page 1 of 1

iPad Gestures: Magazine-style Page Swipes, etc...

Posted: Fri Jun 03, 2011 7:05 pm
by digitalcargo
Hi, all.

I'm just getting started with LiveCode and very excited about the possibilities for iPad apps. I'm specifically looking to swipe from card to card (both horizontally and vertically, if possible) as is done in most iPad magazine apps to navigate from page to page.

I found "visual effect push right fast" which is pretty close, but there isn't any "snappiness" to it. Perhaps done with tweening...?

Also, is there a specific library available for iOS gestures? I'm sure I'll be looking for more of them, too.

Many thanks in advance.

Digitalcargo

Re: iPad Gestures: Magazine-style Page Swipes, etc...

Posted: Sun Jun 05, 2011 1:33 am
by Mark
Hi,

I think there are some visual effects that you can use. Really ought to read the manual.

Kind regards,

Mark

Re: iPad Gestures: Magazine-style Page Swipes, etc...

Posted: Sun Jun 05, 2011 6:28 am
by jacque
Yes, you can do it. You need to use a touchStart handler to store the initial touch location. Then in a touchEnd handler, compare the current location with the stored one. If the horizontal direction is more than so-many pixels (I've seen 10 as an example, but you may want more) then it is considered a swipe. At that point you use the "push left" or "push right" visual effects to move to the next card.

Here is a slightly modified excerpt from the teaching stack we used at the recent RevLive conference. It uses "mouse" handlers instead of "touch" handlers, mostly because they work on both desktop and mobile. You could use either one.

Code: Select all

## Handlers to detect swipe gestures

local hStart,hEnd,vStart
   
on mouseDown   
   # store coords for comparison in mouseUp later:
   put the clickH into hStart
   put the clickH into hEnd
   put the clickV into vStart
end mouseDown

on mouseMove x, y
   put x into hEnd
end mouseMove

on mouseRelease
   mouseUp
end mouseRelease

on mouseUp
   put hEnd - hStart into tDifference
   if tDifference > 10 then
      ## Swipe right
      -- change cards here with "push right"
   else if tDifference < -10 then then
      ## Swipe left
      -- change cards with "push left"
   else
      ## Tap
     -- if you need a tap gesture, the action goes here
   end if
end mouseUp

Re: iPad Gestures: Magazine-style Page Swipes, etc...

Posted: Sun Jun 05, 2011 6:07 pm
by digitalcargo
Thanks, Jacqueline! I'll give that a try... looks like exactly what I need.

digitalcargo