How to slide pages in Corona SDK

天涯浪子 提交于 2020-01-05 07:45:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!