I have a vertical scroll view covering the entire screen. There’s an object that’s not a part of the scroll view, hence the object is fixed on the screen and doesn’t move while scrolling.
Now, while scrolling, when the content position of the Y co-ordinate of the Scroll view goes beyond a particular value, I need the object to scroll along with the scroll view. And the object should again be fixed once the Y co-ordinate of the Scroll view is less than that value.
What are the approaches to go about it?
I’ve done something like this before. I had a little widget that scrolled up out of the bottom when your scrolled down - but it responded to the scroller such that scrolling back up would move it out.
You’ll want to use the scroll listener and move your object when conditions apply. I’ll add my code for reference but it will be different for you.
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")
--event.yDelta
if (ARF.card_customalert_popup and ARF.card_customalert_popup.ready == true) then
if (ARF.card_customalert_popup.startmove == nil) then
ARF.card_customalert_popup.startmove = ARF.card_customalert_popup.y
end
--scrolling down
if (ARF.card_customalert_popup.y >= ARF.card_customalert_popup.startY) then
ARF.card_customalert_popup.y = ARF.card_customalert_popup.startmove - (event.yDelta)
else
if (event.yDelta < 0) then
ARF.card_customalert_popup.y = ARF.card_customalert_popup.startY
end
end
end
elseif (phase == "ended") then
-- print("Scroll view was released")
if (ARF.card_customalert_popup and ARF.card_customalert_popup.ready == true) then
ARF.card_customalert_popup.startmove = ARF.card_customalert_popup.y
end
end
return true
end
1 Like