Author Topic: UIScrollView MoveRelative() and ResetPosition() issue  (Read 5723 times)

fanling3

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 29
    • View Profile
UIScrollView MoveRelative() and ResetPosition() issue
« on: July 17, 2014, 06:11:44 AM »
I am facing a problem that after using
  1. scrollView.MoveRelative(new Vector(-560, 0, 0));
  2. scrollView.ResetPosition();
the x position of the uiScrollView is -65 but not -560,

I traced the code inside ResetPosition(), end up I found the problem is inside SetDragAmount() in UIScrollView.cs, line 573:
  1. if (canMoveHorizontally) pos.x += clip.x - ox
The value of clip.x is 560 and ox is 65, the value of pos.x before assignment is -560, end up the final value of pos.x is -65.

Before this assignment, I found that my another UIScrollView does not have this problem because it returns in line 546
  1. if (b.min.x == b.max.x || b.min.y == b.max.y) return;

Then I figure out the problem because of the gridview setup. For this UIScrollView I have a view like iPhone Home View, where I have 3 x 4 = 12 buttons on ONE page, then I can scroll to another page containing another 12 buttons. I have UIDragScrollView, UIButton, BoxCollider, UISprite, etc for each button.

How to modify to make it works? Thanks.
« Last Edit: July 18, 2014, 12:47:45 AM by fanling3 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView MoveRelative() and ResetPosition() issue
« Reply #1 on: July 18, 2014, 04:36:32 AM »
Each page would logically be its own scroll view. Are you trying to re-populate the same one? What's the issue exactly? That it's not letting you move the scroll view horizontally, since you set it to be limited to vertical movement only? If so, that's intentional for obvious reasons.

fanling3

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIScrollView MoveRelative() and ResetPosition() issue
« Reply #2 on: July 18, 2014, 08:03:54 AM »
Just imagine I am making an iOS Home View, I need to click on each icon to open the app, so I need boxCollider for each UISprite (app icon), right?

And UIDragScrollView needs a collider to work so I can only put UIDragScrollView on each UISprite, end up I am dragging those sprites.

Everytime you quit an app, you will stay on the page you saw last time (for example you scroll to the 3rd page and open an app, you will stay on the 3rd page but not the 1st page after you quit the app), so I have to initialize the localPosition of ScrollView, that's why I am using MoveRelative() and ResetPosition() to achieve this.

That's all what I had and what I want to do. But now the localPosition is wrong after calling these two functions, like what I had mentioned, i want to shift it to left for 560 (-560 for x will let me stay in 2nd page), but the x position is 65 now, end up I am viewing page 1 (shifted a little bit)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView MoveRelative() and ResetPosition() issue
« Reply #3 on: July 19, 2014, 10:24:13 AM »
Don't use MoveRelative. Just restore the scrolled position via UIScrollView's SetDragAmount() function.