Skip to content

Commit a15e973

Browse files
committed
update
1 parent c0cca75 commit a15e973

3 files changed

Lines changed: 1530 additions & 94 deletions

File tree

‎Assets/Runtime/ScrollView/ScrollView.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ void InitScrollView()
577577
content.pivot = Vector2.up;
578578
content.anchorMin = Vector2.up;
579579
content.anchorMax = Vector2.up;
580+
content.anchoredPosition = Vector2.zero;
580581

581582
InitPool();
582583
UpdateRefRect();

‎Assets/Runtime/ScrollView/ScrollViewEx.cs‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class ScrollViewEx : ScrollView
1515
protected override void Awake()
1616
{
1717
base.Awake();
18+
19+
lastPosition = Vector2.up;
1820
onValueChanged.AddListener(OnValueChanged);
1921
}
2022

@@ -27,6 +29,8 @@ protected override void Awake()
2729

2830
private Func<int> realItemCountFunc;
2931

32+
private Vector2 lastPosition;
33+
3034
public override void SetUpdateFunc(Action<int, RectTransform> func)
3135
{
3236
if(func != null)
@@ -80,20 +84,21 @@ protected override void InternalScrollTo(int index)
8084

8185
private void OnValueChanged(Vector2 position)
8286
{
83-
if (reloadFlag)
84-
{
85-
UpdateData(true);
86-
reloadFlag = false;
87-
}
8887

8988
int toShow;
9089
int critical;
9190
bool downward;
9291
int pin;
92+
93+
Vector2 delta = position - lastPosition;
94+
lastPosition = position;
95+
96+
reloadFlag = false;
97+
9398
if (((int)layoutType & flagScrollDirection) == 1)
9499
{
95100
// 垂直滚动 只计算y向
96-
if (velocity.y > 0)
101+
if (delta.y < 0)
97102
{
98103
// 向上
99104
toShow = criticalItemIndex[CriticalItemType.DownToShow];
@@ -105,7 +110,7 @@ private void OnValueChanged(Vector2 position)
105110
pin = critical - 1;
106111
downward = false;
107112
}
108-
else
113+
else if (delta.y > 0)
109114
{
110115
// 向下
111116
toShow = criticalItemIndex[CriticalItemType.UpToShow];
@@ -117,11 +122,15 @@ private void OnValueChanged(Vector2 position)
117122
pin = critical + 1;
118123
downward = true;
119124
}
125+
else
126+
{
127+
return;
128+
}
120129
}
121130
else // = 0
122131
{
123132
// 水平滚动 只计算x向
124-
if (velocity.x > 0)
133+
if (delta.x > 0)
125134
{
126135
// 向右
127136
toShow = criticalItemIndex[CriticalItemType.UpToShow];
@@ -133,7 +142,7 @@ private void OnValueChanged(Vector2 position)
133142
pin = critical + 1;
134143
downward = true;
135144
}
136-
else
145+
else if (delta.x < 0)
137146
{
138147
// 向左
139148
toShow = criticalItemIndex[CriticalItemType.DownToShow];
@@ -145,6 +154,10 @@ private void OnValueChanged(Vector2 position)
145154
pin = critical - 1;
146155
downward = false;
147156
}
157+
else
158+
{
159+
return;
160+
}
148161
}
149162

150163
// 该翻页了 翻半页吧
@@ -174,7 +187,6 @@ private void OnValueChanged(Vector2 position)
174187
// 计算 pin元素的世界坐标
175188
Rect rect = GetItemLocalRect(pin);
176189
Vector2 oldWorld = content.TransformPoint(rect.position);
177-
UpdateData(true);
178190
int dataCount = 0;
179191
if(itemCountFunc != null)
180192
{
@@ -202,7 +214,20 @@ private void OnValueChanged(Vector2 position)
202214
// 取回速度
203215
velocity = oldVelocity;
204216
}
217+
}
218+
219+
public override void OnDrag(PointerEventData eventData)
220+
{
221+
if (reloadFlag)
222+
{
223+
reloadFlag = false;
224+
OnEndDrag(eventData);
225+
OnBeginDrag(eventData);
226+
227+
return;
228+
}
205229

230+
base.OnDrag(eventData);
206231
}
207232
}
208233
}

0 commit comments

Comments
 (0)