scrollView not scrollable when button inside scrollView is touch

my scrollview doesn’t seem to be scrollable anymore when a button is touch even if the button is inside the scrollview.

How can i make the scrollview when a button is touched?
I’m using a button widget by the way [import]uid: 189861 topic_id: 34137 reply_id: 334137[/import]

Short version: You can’t.

widget.newScrollView() does not pass the same kind of events that touch buttons do, so a button placed inside it won’t work properly unless you use return true at the end of the touch listener. But using that line means that only the button registers when you touch it, not anything underneath (so the scroll wouldn’t work)

I’m not aware of any app in iOS that supports both at the same time; if you try to, say, delete an email in mail.app but drag your finger down, the scrollview does not scroll; your finger simply glides off the button.

You could try a user tableView library instead; maybe one of those would work? [import]uid: 41884 topic_id: 34137 reply_id: 135753[/import]

You have to set limits on how far the user moves thier finger. If the user slides thier finger more that 5 pixels then change the focus to the background(scrollview). I worked on this all last week and got it working b e a utifly. Heres an example Mr. Bebee posted about a year ago. Looks something like this:
[lua] if event.phase == “moved” then – Check if you moved your finger while touching

local dx = math.abs( event.x - event.xStart ) – Get the x-transition of the touch-input
local dy = math.abs( event.y - event.yStart ) – Get the y-transition of the touch-input

if dx > 5 or dy > 5 then
scrollView:takeFocus( event ) – If the x- or y-transition is more than 5 put the focus to your scrollview
end[/lua] [import]uid: 46082 topic_id: 34137 reply_id: 135778[/import]

Hmm, interesting sXc, didn’t think of that! [import]uid: 41884 topic_id: 34137 reply_id: 135779[/import]

@sXc I did your suggestions it’s not working the scrollView not moving when i drag. I’m not sure if it actual takes the focus here’s some of my relevant code.

[code]
– this is the code to check if the button is move
local function checkifmoved( event )
if event.phase == “moved” then

local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )

if dx > 5 or dy > 5 then
moveitemscroll:takeFocus( event )
end
end
end [/code]

-- here is the button created  
moveButton = widget.newButton {  
 default = "images/closeBox.png",  
 over = "images/openBox.png",  
 width = 100,  
 height = 100,  
 onRelease = startMove,  
 id = moveID  
 }  
 moveButton.x = 100; moveButton.y = boxy  
  
-- the event listener  
moveButton:addEventListener ("touch", checkifmoved )  

what seems to be the problem with my code? [import]uid: 189861 topic_id: 34137 reply_id: 135840[/import]

Okay, I’m not actually sure if this causes any conflict with other code or is against any “Rules” in LUA, but I do this all the time. Your event listener in the button widget needs to use the same function name as your listener. Like this:
[lua]moveButton = widget.newButton {
default = “images/closeBox.png”,
over = “images/openBox.png”,
width = 100,
height = 100,
onRelease = checkifmoved , -------Right Here
id = moveID
}
moveButton.x = 100; moveButton.y = boxy

– the event listener
moveButton:addEventListener (“touch”, checkifmoved )[/lua] [import]uid: 46082 topic_id: 34137 reply_id: 136004[/import]

Short version: You can’t.

widget.newScrollView() does not pass the same kind of events that touch buttons do, so a button placed inside it won’t work properly unless you use return true at the end of the touch listener. But using that line means that only the button registers when you touch it, not anything underneath (so the scroll wouldn’t work)

I’m not aware of any app in iOS that supports both at the same time; if you try to, say, delete an email in mail.app but drag your finger down, the scrollview does not scroll; your finger simply glides off the button.

You could try a user tableView library instead; maybe one of those would work? [import]uid: 41884 topic_id: 34137 reply_id: 135753[/import]

You have to set limits on how far the user moves thier finger. If the user slides thier finger more that 5 pixels then change the focus to the background(scrollview). I worked on this all last week and got it working b e a utifly. Heres an example Mr. Bebee posted about a year ago. Looks something like this:
[lua] if event.phase == “moved” then – Check if you moved your finger while touching

local dx = math.abs( event.x - event.xStart ) – Get the x-transition of the touch-input
local dy = math.abs( event.y - event.yStart ) – Get the y-transition of the touch-input

if dx > 5 or dy > 5 then
scrollView:takeFocus( event ) – If the x- or y-transition is more than 5 put the focus to your scrollview
end[/lua] [import]uid: 46082 topic_id: 34137 reply_id: 135778[/import]

Hmm, interesting sXc, didn’t think of that! [import]uid: 41884 topic_id: 34137 reply_id: 135779[/import]

@sXc I did your suggestions it’s not working the scrollView not moving when i drag. I’m not sure if it actual takes the focus here’s some of my relevant code.

[code]
– this is the code to check if the button is move
local function checkifmoved( event )
if event.phase == “moved” then

local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )

if dx > 5 or dy > 5 then
moveitemscroll:takeFocus( event )
end
end
end [/code]

-- here is the button created  
moveButton = widget.newButton {  
 default = "images/closeBox.png",  
 over = "images/openBox.png",  
 width = 100,  
 height = 100,  
 onRelease = startMove,  
 id = moveID  
 }  
 moveButton.x = 100; moveButton.y = boxy  
  
-- the event listener  
moveButton:addEventListener ("touch", checkifmoved )  

what seems to be the problem with my code? [import]uid: 189861 topic_id: 34137 reply_id: 135840[/import]

Okay, I’m not actually sure if this causes any conflict with other code or is against any “Rules” in LUA, but I do this all the time. Your event listener in the button widget needs to use the same function name as your listener. Like this:
[lua]moveButton = widget.newButton {
default = “images/closeBox.png”,
over = “images/openBox.png”,
width = 100,
height = 100,
onRelease = checkifmoved , -------Right Here
id = moveID
}
moveButton.x = 100; moveButton.y = boxy

– the event listener
moveButton:addEventListener (“touch”, checkifmoved )[/lua] [import]uid: 46082 topic_id: 34137 reply_id: 136004[/import]