I am really stuck here. I am using take focus to transfer a touch event from a button to the scroll view. This works. However, when I scroll again, the button I last touched has it’s event triggered again (I can see the over imagine changing and the logs), even if I’m not touching the button or touching another button. Scrolling again works once I move enough to trigger the takeFocus function. It sseems like teh oriignal button is holding teh focus. I’ve tried manually triggering the cancelled phase, and playing with the setFocus functions but nothing.
Things go back to “normal” when I simply click on another button or the background on the scroll view. This seems to somehow stop this strange relationship. If I click on another button when doing his, it doesn’t actually work and I see the over image get triggered on the original button.
I’ve included a short video of the problem too.
local buttonsGroup = widget.newScrollView { x = CX, y = CY, width = W, height = H, scrollWidth = W, scrollHeight = H, horizontalScrollDisabled = true, hideBackground = true } group:insert(buttonsGroup) local function onLevelButtonRelease(event) print('buttonPhase' .. event.phase) if event.phase == 'began' then event.target.initialY = event.y elseif event.phase == 'moved' and math.abs(event.target.initialY - event.y) \> 10 then buttonsGroup:takeFocus( event ) elseif event.phase == 'ended' then sounds.play('tap') composer.gotoScene('scenes.reload\_game', {params = event.target.id}) end return true end -- Button positioning is grid based, x,y are grid points local x, y = -2, 0 local spacing = 136 for i = 1, composer.getVariable('levelCount') do local button = widget.newButton({ id = i, label = i, labelColor = {default = {1}, over = {0.5}}, font = native.systemFontBold, fontSize = 50, labelYOffset = -10, defaultFile = 'images/buttons/level.png', overFile = 'images/buttons/level-over.png', width = 128, height = 128, x = x \* spacing + CX, y = 32 + y \* spacing + 87, onEvent = onLevelButtonRelease }) buttonsGroup:insert(button) -- Check if this level was completed if databox['level' .. i] then local check = display.newImageRect('images/check.png', 36, 36) check.anchorX, check.anchorY = 1, 1 check.x, check.y = button.width - 3, button.height - 18 button:insert(check) -- Insert after positioning, because if inserted before, button.width/height will be different end x = x + 1 if x == 3 then x = -2 y = y + 1 end end