Author Topic: Restricting a ScrollView when using CenterOnChild  (Read 3918 times)

apomarinov

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Restricting a ScrollView when using CenterOnChild
« on: February 16, 2016, 04:21:45 AM »
Hello  :)

I have a scrollview that is controlled only by going up and down the elements without scroll/drag and I need it to be centered. When the element is changed I pass the new one to UICenterOnChild.CenterOn and the view is centered appropriately. The problem is that when it centers lets say the 1st element, the whole view is brought down so the 1st element is in its center. When the scrolling is over, if I go and try to change the Y-pos of the scrollview it snaps to the top exactly how it should be. Also I saw that CenterOnChild uses a SpringPanel static function to scroll the view but that doesn't make the checks if it should be moved. So is there a way to restrict the view from pulling the top elements to the center?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Restricting a ScrollView when using CenterOnChild
« Reply #1 on: February 18, 2016, 06:53:32 PM »
If you don't want it to scroll to center on the item then don't use UICenterOnChild. :P

Write your own code. Instead of SpringPanel.Begin to the position of the child, calculate -- is the desired position within some range based on the known size of the elements and/or the scroll view's dimensions? If not, limit the position so that it is, and only then SpringPanel.Begin.

apomarinov

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Restricting a ScrollView when using CenterOnChild
« Reply #2 on: February 19, 2016, 02:40:54 AM »
Hey, thanks for answering, you are right. I ended up putting this clamp in the SpringPanel's update:
  1. after.y = Mathf.Clamp(after.y, mDrag.panel.baseClipRegion.w * 0.5f - mDrag.panel.clipSoftness.y * 0.5f, Mathf.Infinity);
I dont think its universal though, because it doesnt work on some of the other scrollviews I have, that are using contentOrigin - top. I hope I`ll be able to tune them too.