Hello everyone,
I want to use swipe feature on scroll view widget. Actually the problem is when I try to swipe left or right on scroll view widget, it never calls swipe function. Only scroll listener is being called every time.
The task is to change the text inside scroll view if a user swipes left or right direction and also should be able to scroll up and down.
Here is my code,
local getText local getHadithNo = 1 local function scrollListener( event ) local phase = event.phase if ( phase == "began" ) then print( "touched" ) elseif ( phase == "moved" ) then print( "moved" ) elseif ( phase == "ended" ) then print( "released" ) end if ( event.limitReached ) then if ( event.direction == "up" ) then print( "bottom limit" ) elseif ( event.direction == "down" ) then print( "top limit" ) elseif ( event.direction == "left" ) then print( "right limit" ) elseif ( event.direction == "right" ) then print( "left limit" ) end end return true end local scrollView = widget.newScrollView( { top = 180, left = 0, width = display.contentWidth + 4, height = display.contentHeight - 178, topPadding = 10, bottomPadding = 10, horizontalScrollDisabled = true, verticalScrollDisabled = false, hideBackground = true, listener = scrollListener } ) local function displayText() getText = display.newText(\_G.getClass.getHadith("No: "..getHadithNo) , 0, 0, display.contentWidth - 15, 0, "BRONSON.TTF", vals[3]) getText:setTextColor(255, 255, 255) getText.anchorY = 0 getText.x = display.contentCenterX scrollView:insert(getText) end local prevHadith = function(event) if event.phase == "ended" then if getHadithNo \> 1 then getHadithNo = getHadithNo - 1 getHadithText.text = "Hadith Qudsi "..getHadithNo scrollView:remove(getText) getText.text = \_G.getClass.getHadith("No: "..getHadithNo) scrollView:insert(getText) end end end local nextHadith = function(event) if event.phase == "ended" then if getHadithNo \< 41 then getHadithNo = getHadithNo + 1 getHadithText.text = "Hadith Qudsi "..getHadithNo scrollView:remove(getText) getText.text = \_G.getClass.getHadith("No: "..getHadithNo) scrollView:insert(getText) end end end local function swipe(event) if ( event.phase == "ended" or event.phase == "cancelled" ) then local dif = event.xStart-event.x if dif \> 30 then nextHadith(event) elseif dif \< -30 then prevHadith(event) end end return true end function myMain() displayText() Runtime:addEventListener("touch", swipe) end myMain()
Any help would be highly appreciated.
Thanks,