1

I'm using CORONA SDK. I have a set of pages and I would like to slide between them using swipe left -right. The page contains a set of controls (mostly text)

What is the best way to do this slide/swipe in Corona?

gflower
  • 125
  • 2
  • 13

2 Answers2

1

Using touch events.

When the phase of event is "began" (The user just touched the screen), allow the three pages to move (the actual, the forwards and the backwards).

if event.phase == "began" then

    page1.canMove = true
    page2.canMove = true
    page3.canMove = true
    initial = {}
    initial.x = event.x
 end

If the pages are allowed to move:

if page1.canMove == true then

Move the three pages according to the x parameter of event.

page1.x = page1.x + event.x - initial.x
page2.x = page2.x + event.x - initial.x
page3.x = page3.x + event.x - initial.x

when the phase of event is "end" (The user release the finger), remove the permission to move.

if event.phase == "end" then
    page1.canMove = false
    page2.canMove = false
    page3.canMove = false
end

and adjust the pages, depending on where they are.

I just invented this solution, if someone can contribute to make it more complete :D.

Chirry
  • 640
  • 6
  • 12
0

You can do this by using the transitions of the Storyboard

In storyboard, page is a scene, you can add transitions.

http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/
NaviRamyle
  • 3,967
  • 1
  • 31
  • 49
  • Actually all pages are similar so I have only one scene. I have read that it's not recommended to use gotoScene in Storyboard for the same scene : http://forums.coronalabs.com/topic/34605-storyboard-gotoscene-drops-options-passed-to-if-you-are-going-to-the-same-scene/ – gflower Jun 21 '13 at 10:15