The button does not work when I have scroll, how to fix it?
main file:
[lua]local composer = require( “composer” )
composer.gotoScene(“menu”)
[/lua]
menu file:
[lua]
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
– ScrollView listener
local function scrollListener( event )
local phase = event.phase
if ( phase == “began” ) then print( “Scroll view was touched” )
elseif ( phase == “moved” ) then print( “Scroll view was moved” )
elseif ( phase == “ended” ) then print( “Scroll view was released” )
end
– In the event a scroll limit is reached…
if ( event.limitReached ) then
if ( event.direction == “up” ) then print( “Reached bottom limit” )
elseif ( event.direction == “down” ) then print( “Reached top limit” )
elseif ( event.direction == “left” ) then print( “Reached right limit” )
elseif ( event.direction == “right” ) then print( “Reached left limit” )
end
end
return true
end
local function onScrollComplete()
print( “Scroll complete!” )
end
– Create the widget
local scrollView = widget.newScrollView(
{
top = -45,
left = 0,
width = 320,
height = 570,
scrollWidth = 0,
scrollHeight = 0,
topPadding = 50,
–bottomPadding = -100
horizontalScrollDisabled = true,
listener = scrollListener
}
)
local function ChangeScenes ()
composer.gotoScene( “scene1”, {effect = “slideLeft”, time=100})
end
– create()
function scene:create( event )
local sceneGroup = self.view
background = display.newImageRect( “background.png”, 360, 570 )
background.x = display.contentCenterX
background.y = display.contentCenterY
sceneGroup:insert(background)
scrollView:insert(background)
local label1 = display.newImage( “label.png”, 160, 0)
label1:addEventListener (“tap”, ChangeScenes)
sceneGroup:insert(label1)
scrollView:insert(label1)
scrollView:setScrollHeight(500)
end
– show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
– Code here runs when the scene is entirely on screen
end
end
– hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == “did” ) then
– Code here runs immediately after the scene goes entirely off screen
end
end
– destroy()
function scene:destroy( event )
local sceneGroup = self.view
– Code here runs prior to the removal of scene’s view
end
– Scene event function listeners
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene[/lua]