Author Topic: ClipRange Dislocated After moving the panel...  (Read 5960 times)

cheuksh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
ClipRange Dislocated After moving the panel...
« on: January 15, 2014, 02:38:50 PM »
I have a vertical scroll view with about 200 item, when user scroll to item 160-180, clicked a back button, changed their location, all of the scroll item are then removed and another 200 items are added from the database. Everything work smoothly.

However, all item disappear from the screen..I checked the scrollview, it is find that the scrollview is still in its old position (at item 16(making item 1-20 far away from the screen) ...so I reset it mannually:
  1. ScrollViewGO.transform.localPosition= new Vector3(ScrollViewGO.transform.localPosition.x,OriginalScrollViewY, 0);
now the location is correct but I still cannot see the item and I find that the clip range positions is moved....I think it is not the good way to reset like this....

Is it anyway to easily reset the scrollview, once all the items inside are replaced by a new set of items?
« Last Edit: January 15, 2014, 03:12:06 PM by cheuksh »

cheuksh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: ClipRange Dislocated After moving the panel
« Reply #1 on: January 15, 2014, 03:11:28 PM »
In short, to reproduce, make a vertical scroll view, scroll it, clip region doesn't change, but the transform local position y of the panel will change. If we type a different value to the local position y in the inspector. So this some how tell me that if I change the transform local position y, clip range will move together..(.I don't wanna offset it back...it is urgly...)

Clip Region move together..so how can I change the scroll view back to the first row while not moving the clip range...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ClipRange Dislocated After moving the panel...
« Reply #2 on: January 15, 2014, 09:24:03 PM »
Don't modify the transform at all. Reset the scroll position before and after making modifications to your content.

cheuksh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: ClipRange Dislocated After moving the panel...
« Reply #3 on: January 15, 2014, 10:52:17 PM »
Thx a lot, glad to hear that we can move the scroll view..I should have checked the functions in UIScrollView...and Google how to reset position....Turn out the following works for me:
Method 1 SpringPanel.Begin(ScrollViewGO, new Vector3(ScrollViewGO.transform.localPosition.x, -1240, 0), 999999999);
Method 2 ScrollViewGO.GetComponent<UIScrollView>().MoveRelative(new Vector3(0, - ScrollViewGO.transform.localPosition.y - 1240, 0));
But the following not work for me:
ScrollViewGO.GetComponent<UIScrollView>().ResetPosition();

SpringPanel method can do the trick but...is kind of urgly, I don't need spring effect and movement, I just need reposition...MoveRelative is much elegant but it need me to recalculate the difference of the position in order to move, Should it be some function like scrollTo,scrollToTop,scrollToBottom function in uiscrollview..? To keep it consistent, hope there will be MoveTo(), MoveToBottom(), MoveToTop() function in uiscrollview in the future. NGUI is the greatest plugin in unity! Really thx a lot!