问题
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?
回答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.
回答2:
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/
来源:https://stackoverflow.com/questions/17218232/how-to-slide-pages-in-corona-sdk