I have a UI with a scrollview within a scrollview. The outer scrollview scrolls horizontally and the inner scrollview scrolls vertically. For the most part this arrangement works really nicely - the outer scroll view contains summary information and the inner one specifics which the user can scroll past if they are not interested or scroll through for more detail. However on occasion the inner scrollview stops scrolling and responding to touch events
There’s a bit of code to make sure that the user can only scroll one scroll view at a time, so if scrolling horizontally, they need to stop before they can scroll vertically. The code for both scrollviews is:
[lua]
local rect=display.newRect(0,0,100,100)-- an example first element
local scrollPadding=(display.contentWidth-rect.width)/2
local scrollview=widget.newScrollView({
verticalScrollDisabled=true,
hideBackground=true,
hideScrollBar=true,
leftPadding=scrollPadding,
rightPadding=scrollPadding,
})
scrollview:insert(rect)
scrollview:scrollToPosition({x=rect.x-rect.width/2+scrollPadding})
local stageScrollView=widget.newScrollView({
horizontalScrollDisabled=true,
hideBackground=true,
bottomPadding=scrollPadding,
hideScrollBar=true,
listener=(function()
local lx,ly
local scrollingHorizontally
local locked
return function(event)
if event.phase==“began” then
lx=event.x
ly=event.y
scrollingHorizontally=false
locked=false
end
if event.phase==“moved” then
local dx=event.x-lx
local dy=event.y-ly
lx,ly=event.x,event.y
scrollingHorizontally=not locked and dx*dx>dy*dy or scrollingHorizontally
local dx=event.x-event.xStart
local dy=event.y-event.yStart
if dx*dx+dy*dy>20*20 then
locked=true
end
if scrollingHorizontally then
scrollview:takeFocus(event)
end
end
end
end)()
})
scrollview:insert(stageScrollView)
stageScrollView.x=rect.x+rect.width+padding
[/lua]
I was wondering if anyone has had a similar problem, and whether there’s any work arounds to ensure a more robust experience. Or is there a bug in my code?