iOS iPhone 'swipe' only with selected card 'range'

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
edwardcox
Posts: 3
Joined: Wed Oct 12, 2011 10:42 am

iOS iPhone 'swipe' only with selected card 'range'

Post by edwardcox » Tue Oct 18, 2011 5:12 am

Hello All,

Thanks for looking at my request. I'm using LC 5, with iOS and Android. In my current iOS project I want to implement a nice 'swipe' catalog, with an image/item on each card, perhaps 10 cards in total (that could be a group?) that contain the products. The other cards do not contain products (login, register, etc.).

So, I use the example code to implement the 'swipe' technique:

Code: Select all

# the event id and initial swipe time and position
local sTouchId, sInitTime, sInitX


# maximum swipe time in millisecs
local sSwipeTime


# minimum swipe distance
local sSwipeDistance


on openStack
   # set up swipe values - experiment with these for required effect
   put 500 into sSwipeTime
   put 150 into sSwipeDistance
end openStack


on touchMove pId, pX, pY
   if pId <> sTouchId then
      # record initial values for start of swipe
      put pId into sTouchId
      put the millisecs into sInitTime
      put pX into sInitX
   end if
   
   # check the action was fast enough for a swipe
   if the millisecs - sInitTime <= sSwipeTime then
      # check we have covered enough distance
      put pX - sInitX into tDistanceX
      if abs(tDistanceX) > sSwipeDistance then
         if tDistanceX < 0 then
            # finger is swiping left
            send "swipeLeft" to me in 0 millisecs
         else
            # finger is swiping right
            send "swipeRight" to me in 0 millisecs
         end if
      end if
   end if
end touchMove


command swipeLeft
   visual effect scroll left normal
   go prev card
end swipeLeft


command swipeRight
   visual effect scroll right normal
   go next card
end swipeRight
however, this is in the Main Stack code and so is applied to ALL Cards.

What I want to achieve is allowing only the 'Product' Cards to be 'swiped' left or right.

Is there a way to 'Group' together a range or group of Cards in a Stack?

And then am I able to restrict which Cards are 'swipeable' (is that even a word??)?

Thanks again for your kind understanding and patience with a noob.

Regards,

Ed
Icon Visual Marketing
Camden, NSW

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: iOS iPhone 'swipe' only with selected card 'range'

Post by FireWorx » Tue Oct 18, 2011 7:53 am

Hi,
You can just remove the above script from the stack and copy it into the card script of each card you would like to have swipe ability on. Then just change

on openStack
   # set up swipe values - experiment with these for required effect
   put 500 into sSwipeTime
   put 150 into sSwipeDistance
end openStack

TO
on openCard
   # set up swipe values - experiment with these for required effect
   put 500 into sSwipeTime
   put 150 into sSwipeDistance
end openCard

This works I tested it. I am positive there is a cleaner way to do this but not sure what it is off hand. Perhaps one of the guru's can chirp in although they have been pretty mute lately.
Dave

edwardcox
Posts: 3
Joined: Wed Oct 12, 2011 10:42 am

Re: iOS iPhone 'swipe' only with selected card 'range'

Post by edwardcox » Tue Oct 18, 2011 11:30 am

FireWorx wrote:Hi,
You can just remove the above script from the stack and copy it into the card script of each card you would like to have swipe ability on. Then just change

on openStack
   # set up swipe values - experiment with these for required effect
   put 500 into sSwipeTime
   put 150 into sSwipeDistance
end openStack

TO
on openCard
   # set up swipe values - experiment with these for required effect
   put 500 into sSwipeTime
   put 150 into sSwipeDistance
end openCard

This works I tested it. I am positive there is a cleaner way to do this but not sure what it is off hand. Perhaps one of the guru's can chirp in although they have been pretty mute lately.
Dave
Thanks Dave, that's a great idea.

Ed

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: iOS iPhone 'swipe' only with selected card 'range'

Post by jacque » Tue Oct 18, 2011 6:02 pm

The easiest way is to create a background group that contains the swipe cards. Then put the handlers into the background script.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 157
Joined: Thu Jun 29, 2006 4:16 pm

Re: iOS iPhone 'swipe' only with selected card 'range'

Post by Randy Hengst » Tue Oct 18, 2011 6:05 pm

You could also leave the script at the stack level and use a switch statement... something like this....


on touchMove pId, pX, pY
local tDistanceX

switch short name of current card
case "Card1" -- list only the names of the cards where the swipe will work....
case "Card2"
case "Card3"
   if pId <> sTouchId then
      # record initial values for start of swipe
      put pId into sTouchId
      put the millisecs into sInitTime
      put pX into sInitX
   end if
   
   # check the action was fast enough for a swipe
   if the millisecs - sInitTime <= sSwipeTime then
      # check we have covered enough distance
      put pX - sInitX into tDistanceX
      if abs(tDistanceX) > sSwipeDistance then
         if tDistanceX < 0 then
            # finger is swiping left
            send "swipeLeft" to me in 0 millisecs
         else
            # finger is swiping right
            send "swipeRight" to me in 0 millisecs
         end if
      end if
   end if
break
end switch
end touchMove

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: iOS iPhone 'swipe' only with selected card 'range'

Post by quailcreek » Fri Jun 27, 2014 12:27 am

Thought I resurrect this old post as I am working on something similar.

I think most are familiar with this tutorial on the LC site.
http://lessons.runrev.com/m/4069/l/2960 ... r-the-ipad

I changed a few lines of code to allow the cards that are swiped to be between the first and last marked card of the stack. It could also be done using uProps for the controlling cards to be swiped.

I changed the forward and backward handlers to this:

Code: Select all

on moveForward
   if the number of this marked cd < tLastCardNum then 
      visual effect push left
      go next marked cd
   else
      if the number of this marked cd = tFirstCardNum then 
         exit to top
      end if
   end if
end moveForward

on moveBack
   if the number of this marked cd > tFirstCardNum then 
      visual effect push right
      go previous marked cd
   else
      if the number of this marked cd = tLastCardNum then 
         exit to top
      end if
   end if
end moveBack
And the touchSart handler to add setting the tFirstCardNum and tLastCardNum local variables.

Code: Select all

on touchStart pID
   ## When the user touches the screen t
   put empty into sCoordinateArray["start"]
   put empty into sCoordinateArray["end"]
   
   put the number of the first marked cd of this stack into tFirstCardNum ## This was added
   put the number of the last marked cd of this stack into tLastCardNum ## This was added
end touchStart
On the touchEnd handler I added the top if statement to have it run only on marked cards:

Code: Select all

on touchEnd
   put sCoordinateArray["start"] into tStart
   put sCoordinateArray["end"] into tEnd
   
   if the mark of this cd is true then ## This was added
      if tStart is not empty and tEnd is not empty then
         if tStart > tEnd  and tStart - tEnd > 50 then
            moveForward
         else 
            if tStart < tEnd and tEnd-tStart > 50 then
               moveBack
            end if
         end if
      end if
   end if
   put empty into sCoordinateArray["start"]
   put empty into sCoordinateArray["end"]
end touchEnd
HTH
Tom
Tom
MacBook Pro OS Mojave 10.14

Post Reply