Using the GUILayout scrollview (on android at least) seems to cause some strange behaviour.
When scrolling all the way down to the end of its content, and then scrolling some more, it seems that the scrollpos is actually going down further (without actually scrolling the scrollview tho), causing the scrollview not to scroll right back up, but only after a few swipes.
I think I need to clamp the scrollpos, but I don’t know what values to use. Anyone know? Or is this just some bug caused by some random piece of code in my scripts?
1 Answer
1
Found it! the scrollpos does need to be clamped, you can do this by using the following code, if anyone is interested:
scrollPos.y = Mathf.Clamp(scrollPos.y,0,Screen.height);
scrollPos.x = Mathf.Clamp(scrollPos.x,0,Screen.width);
just adding this at the end of whatever code you use to change the scrollpos variable will clamp it.
If you’re certain you will only scroll one way, you can leave either the x or y line out.
In this piece of code the scrollview is clamped to the screen dimensions(0 and height/width), but this should be whatever rectangle you use for your scrollview.
EDIT: after some testing I found out I need to clamp to the dimensions of the content inside the scrollview to make it work properly. I have no idea how to do that sadly. So the question still remains unanswered! D:
EDIT2: Okay nevermind me, now I get why it didn’t work in the first place. There is no need to clamp it, it just so happens I used
GUILayout.BeginScrollView(scrollPos);
instead of:
scrollPos = GUILayout.BeginScrollView(scrollPos);
which clamps it correctly. Why do I read over such obvious things?