- Home /
ScrollView/ScrollRect scrolling "refresh" event?
Hi,
i have a question that refers to the possibilities of ScrollViews / Scrollrects in Unity. Is it possible to get a similar result like this ?
I created a ScrollView with the "Movement Type" elastic so this works partly. But is there an event that triggers when i "scroll too far?"
Answer by FernandoHC · Aug 20, 2018 at 10:14 AM
Yes you can achieve that same result, unfortunately scrollRect is a bit limited in that regard, so what I do is to have 2 objects relative to the top position of the scrollRect panel and one object relative to the top position of the Content panel, then calculate their distance. I then calculate the distance on the event:
scrollRect.onValueChanged.AddListener(OnScrollRectChange);
private void OnScrollRectChange(Vector2 position)
{
if (loading || !enableScrollLoadMore)
return;
// Detect if more messages should be loaded
if (loadMoreObjectPosition.transform.position.y < loadMorePivotBottom.transform.position.y - 20)
{
Debug.Log("Load more relics");
}
}
You could also use the position vector2 param of the event to observe the value of the scrolling and use that, just be careful because that value is relative to the size of the content and will vary depending on it.
Short question: What is the purpose of this Code-Block? @FernandoHC
if (loading || !enableScrollLoad$$anonymous$$ore)
return;
Because this code is in the same class as the network request call I do to the server, I have the loading = true while the server request is waiting to be completed (takes about a fraction of a second, but we don't want to call the same request again while it is loading).
The enableScrollLoad$$anonymous$$ore is another controller I have in the UI, when I don't want it to load for any other reason, like while the gameobject has not been initialized yet, or if the user is spam$$anonymous$$g, etc.
Okay i understand that thank you! That sounds reasonable, i will implement it too, great hint.
Your answer
Follow this Question
Related Questions
Moving a ScrollRect child via script to focus on some point. 0 Answers
How can I programmatically tween a Scroll View to a desired position? 0 Answers
Scroll View: Is there a way to discriminate and accept only certain PointerEvents? 0 Answers
Scaling scroll view width to its content width or vice versa 0 Answers
Scrollbar touch sensitivity 0 Answers