Hi,
I recently discovered an issue with UIScrollView regarding UICenterOnChild and IOSDragEmulation.
A quick repro:
- Open Example 7 - Scroll View (Panel)
- Start playing, and activate Center on Items
- Go to and center to the first item
- Drag the first item towards right -> iOSDragEmulation does it job and slows down the drag
- Go to and center to the first item again
- Now drag the first item towards left -> iOSDragEmulation is slowing down the drag even it shouldn't. When the first item reaches the left side edge of the scroll view bounds, drag returns to normal speed.
The reason for this behavior is because the iOSDragEmulation is applied when the scroll view contents are considered out of bounds (and this is due to the UICenterOnChild). If you disable UICenterOnChild, it works as the first item now sticks to the left side of the scroll view boundaries if you scroll to the first item.
I don't have any easy fix for this. What I've done in one project is to set the scroll view bounds to exact size of the one scrollable item, and then set the clipping mode to ConstrainButDontClip. However, after that the dragging from outside the bounds didn't work, and I needed to fix UIPanel.IsVisible(Vector3 worldPos) like this:
public bool IsVisible (Vector3 worldPos)
{
if (mAlpha < 0.001f) return false;
if (mClipping == UIDrawCall.Clipping.None) return true;
// BEGIN FIX
if (mClipping == UIDrawCall.Clipping.ConstrainButDontClip) return true;
// END FIX
UpdateTransformMatrix();
Vector3 pos = worldToLocal.MultiplyPoint3x4(worldPos);
if (pos.x < mMin.x) return false;
if (pos.y < mMin.y) return false;
if (pos.x > mMax.x) return false;
if (pos.y > mMax.y) return false;
return true;
}
I'm not sure if IsVisible should work differently with ConstrainButDontClip, but as it has no clipping, and Clipping.None always returns true, it seemed reasonable. However, this doesn't fix the iOSDragEmulation issue, it's just a workaround. ConstainButDontClip doesn't allow you to use nice alpha clipping.
I think the fundamental issue is that clipping bounds and constraint bounds should really be different ones... but that would require a fundamental change to the UIPanel logic.
What do you guys think?
Cheers,
Sampsa Lehtonen / Draconus Entertainment