Author Topic: Restrict UIScrollView movement  (Read 5627 times)

johns

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Restrict UIScrollView movement
« on: July 02, 2014, 04:40:33 AM »
Hi,

How can I make sure that the user won't be able to scroll outside of a panel? I would like the user to never be able seeing anything outside of the panel.



I'd like the scrollview to prevent user from scrolling up in this case.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Restrict UIScrollView movement
« Reply #1 on: July 02, 2014, 06:00:21 AM »
It's an option on the UIScrollView: Drag Effect. Instead of MomentumAndSpring, choose Momentum or None.

johns

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Re: Restrict UIScrollView movement
« Reply #2 on: July 02, 2014, 06:30:35 AM »
None of the options seem to return the scrollview to the original position - it's still at the position where the user left it. I'd like the icons in the screenshot to return back to the top when user lets go of the mouse.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Restrict UIScrollView movement
« Reply #3 on: July 03, 2014, 03:47:44 AM »
Your question was how to prevent the user from scrolling outside of the panel. MomentumAndSpring is what lets the scroll view to scroll past the panel's contents, followed by a spring back into place. If you want it to return to some position XYZ instead, you should use SpringPanel yourself (SpringPanel.Begin).

johns

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Re: Restrict UIScrollView movement
« Reply #4 on: July 03, 2014, 09:35:54 AM »
My problem is that even with MomentumAndSpring enabled the scroll view doesn't spring back into place. "Restrict within panel" is on.

After doing some testing it turned out that the SpringPanel script never gets attached to my scroll view. In the RestrictWithinBounds method constraint.sqrMagnitude is always zero, therefore the if statement that creates the SpringPanel never gets called. Do you have any idea what might be wrong?

Thanks.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Restrict UIScrollView movement
« Reply #5 on: July 03, 2014, 06:53:51 PM »
Scrollview does not automatically re-center itself with any setting. This is something you have to do yourself. You can use SpringPanel to make it do this, but you have to do it manually.

The None, Momentum, MomentumAndSpring only covers how the behavior is when you drag the scrollview, so momentum adds "weight" to the panel, so it doesn't stop instantly when you release your touch, momentumAndSpring makes it possible to drag the panel contents within the scrollview like in iOS, but makes it bounce back to fit the edges.

johns

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Re: Restrict UIScrollView movement
« Reply #6 on: July 03, 2014, 09:08:28 PM »
I don't need the scrollview to center on anything - I just need it to "bounce back to fit the edges", just like in the "Example 7 - Scroll View (Panel)" demo. But this isn't happening with my scene.

None of the following statements in ConstraintRect ever get called for me:
      if (minRect.x < minArea.x) offset.x += minArea.x - minRect.x;
      if (maxRect.x > maxArea.x) offset.x -= maxRect.x - maxArea.x;
      if (minRect.y < minArea.y) offset.y += minArea.y - minRect.y;
      if (maxRect.y > maxArea.y) offset.y -= maxRect.y - maxArea.y;

Maybe there's something wrong with the setup of my ScrollView?

Thanks.

johns

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Re: Restrict UIScrollView movement
« Reply #7 on: July 03, 2014, 09:53:32 PM »
After recreating the ScrollView from scratch the issue was resolved. Magic? :)

johns

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Re: Restrict UIScrollView movement
« Reply #8 on: July 03, 2014, 10:03:17 PM »
Found the issue - it turned out that one of the elements within the scroll view was anchored to the Root UiPanel. Thank you for your time.