PageComponent为定义创建一个内容页层,可以快速、方便的进行页面创建,且自动支持滑动翻页效果。
代码如下:
Page = new PageComponent
width: Screen.width
height: Screen.height
scrollVertical: false
Layer1 = new Layer
width: Page.width
height: Page.height
superLayer: Page.content
x:0
y:0
image: "images/1.png"
Layer2 = new Layer
width: Page.width
height: Page.height
superLayer: Page.content
x:Page.width
y:0
image: "images/2.png"
Layer3 = new Layer
width: Page.width
height: Page.height
superLayer: Page.content
x:Page.width * 2
y:0
image: "images/3.png"
Layer4 = new Layer
width: Page.width
height: Page.height
superLayer: Page.content
x:Page.width * 3
y:0
image: "images/4.png"
#按钮定义
Button1 = new Layer
width: Page.width/4
height:100
x:0
y:Page.height - 100
opacity: 0
Button2 = new Layer
width: Page.width/4
height:100
x:Page.width/4
y:Page.height - 100
opacity: 0
Button3 = new Layer
width: Page.width/4
height:100
x:Page.width/2
y:Page.height - 100
opacity: 0
Button4 = new Layer
width: Page.width/4
height:100
x:Page.width/2+Page.width/4
y:Page.height - 100
opacity: 0
#定义菜单切换按钮
Button1.on Events.Click, ->
Page.snapToPage(Layer1) //snapToPage() 跳转到指定的Page
Button2.on Events.Click, ->
Page.snapToPage(Layer2)
Button3.on Events.Click, ->
Page.snapToPage(Layer3)
Button4.on Events.Click, ->
Page.snapToPage(Layer4)