如何在Corona SDK中滑动页面 [英] How to slide pages in Corona SDK

查看:118
本文介绍了如何在Corona SDK中滑动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CORONA SDK。我有一组页面,我想使用左右滑动在它们之间滑动。该页面包含一组控件(主要是文本)

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)

在Corona中执行此幻灯片/滑动的最佳方法是什么?

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

推荐答案

使用触摸事件。

当事件的阶段开始时(用户只需触摸屏幕),请允许三个页面移动(实际,向前和向后)。

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 page1.canMove == true then

根据事件的x参数移动三个页面。

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

活动阶段是 end(用户松开手指),请删除移动权限。

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.

我只是发明了这种解决方案,如果有人可以使它更完整:D。

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

这篇关于如何在Corona SDK中滑动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆