Unity Scroll View Content position reset
유니티에서 스크롤로 쭉 내린 후에, 다른 페이지 갔다가 다시 진입하면
그 위치 그대로 스크롤이 내려져 있다.
-> 맨 위 리스트를 보기 위해서 위치를 초기화 하려고 한다.
한참 찾았는데 단순한 rect 위치 문제였다. 간단히 해결!
다들 헤매는 이유는
position 으로 접근한듯
anchoredPosition 임!
1
2
3
4
5
6
7
8
|
public RectTransform ScrollContent;
public void setRectPosition() {
float x = ScrollContents.anchoredPosition.x;
ScrollContents.anchoredPosition = new Vector3(x, 0, 0);
}
|
c |
Positioning the UI element
A UI Element is normally positioned using its Rect Transform. If the UI Element is a child of a Layout Group it will be automatically positioned and the positioning step can be skipped.
When positioning a Rect Transform it’s useful to first determine it has or should have any stretching behavior or not. Stretching behavior happens when the anchorMin and anchorMax properties are not identical.
For a non-stretching Rect Transform, the position is set most easily by setting the anchoredPosition and the sizeDelta properties. The anchoredPosition specifies the position of the pivot relative to the anchors. The sizeDelta is just the same as the size when there’s no stretching.
For a stretching Rect Transform, it can be simpler to set the position using the offsetMin and offsetMax properties. The offsetMin property specifies the corner of the lower left corner of the rect relative to the lower left anchor. The offsetMax property specifies the corner of the upper right corner of the rect relative to the upper right
'DEV > Unity' 카테고리의 다른 글
[solved] unity UI Text Color change separately 부분 색 바꾸기 (0) | 2020.12.26 |
---|---|
Unity Atlas 정리 및 이미지 최적화 정리 (2) | 2020.12.22 |
Unity ads error Banner fail (0) | 2020.12.19 |
[solved] UnityWebRequest Get noneArray Type error (0) | 2020.12.19 |
NullReferenceException: Object reference not set to an instance of an objectUnityEditor.Graphs.Edge.WakeUp () (0) | 2020.05.17 |