Author Topic: Limit UIScrollView render dimensions  (Read 3792 times)

Retribution

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Limit UIScrollView render dimensions
« on: May 26, 2016, 11:26:10 PM »
Hello all,

I'm running into a situation where I'd like to override the min/max scroll area of the UIScrollView.  Currently my hierarchy is setup as follows:

| UIScrollView
---| UIGrid
--------| Sprite 1
--------| Sprite 2
--------| Sprite N

In this example, let's say all that the total height of rendering all of my sprites extends from Vector3(0, 0, 0) to Vector3(0, 1500, 0).  However, due to masking and just not wanting to allow players to scroll all the way to the bottom of the scrollview, I wanted to limit the scrollview to only allow players to scroll from Vector3(0, 0, 0) to Vector3(0, 1200, 0).

It looks like in the UIScrollView, it's calculating the total width/height of the children elements to the scrollview and setting its scroll area to cover all renderable assets.  Is there an easier way to prevent this behaviour that I'm not aware of outside of modifying the script?  I tried limiting the Offset on the UIPanel attached to the UIScrollView, but that resulted in unexpected behaviour (possibly because I attempted to limit the values incorrectly).

Any ideas how I can achieve this?  Any tips or pointers on setup would be appreciated - thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Limit UIScrollView render dimensions
« Reply #1 on: May 27, 2016, 10:23:30 PM »
Well... the scroll view script is written to automatically calculate the dimensions of the content within. In your case you seem to want to overwrite this behaviour. You can do this by creating a custom script derived from UIScrollView and overwriting the 'bounds' property. Adjust the bounds as you see fit (such as reducing the height by 300).