Author Topic: Horizontal drag triggers threshold on vertical UICenterOnChild  (Read 3797 times)

pigi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Horizontal drag triggers threshold on vertical UICenterOnChild
« on: February 13, 2014, 03:37:26 PM »
Hello!

I'm using nested UIScrollViews to implement a bidimensional list whose lines and columns are navigated independently. Both lines and columns use UICenterOnChild with a threshold. Now, I notice that only the x value of the touch delta is used to check the threshold. It seems it was implemented as an answer to the use case described in the following thread, which only uses horizontal "pages" :

http://www.tasharen.com/forum/index.php?topic=6999.msg33013#msg33013

I think this might be a bug? Maybe I'm missing something here, but I modified UICenterOnChild.Recenter() to check UIScrollView.Movement and pick either the x or y component of the delta for Horizontal and Vertical scroll views, and the magnitude for Unrestricted. Works great for me! I'm not sure what Custom should use though. I will leave that up to you as we don't have a use for it as of yet. :)

Here's the code I added to the nextPageThreshold conditional:

  1.                                 float directionDelta;
  2.  
  3.                                 switch (mScrollView.movement)
  4.                                 {
  5.                                         case UIScrollView.Movement.Horizontal:
  6.                                         {
  7.                                                 directionDelta = delta.x;
  8.                                                 break;
  9.                                         }
  10.                                         case UIScrollView.Movement.Vertical:
  11.                                         {
  12.                                                 directionDelta = delta.y;
  13.                                                 break;
  14.                                         }
  15.                                         // Unrestricted and Custom (?)
  16.                                         default:
  17.                                         {
  18.                                                 directionDelta = delta.magnitude;
  19.                                                 break;
  20.                                         }
  21.                                 }
  22.  
  23.                                 //if (directionDelta > nextPageThreshold)
  24.                                 //...
  25.  

On a side note, I think that the term "page" is slightly confusing, as it is clearly UI-related but isn't officially used by NGUI. Maybe "child" or "item" would be more appropriate?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Horizontal drag triggers threshold on vertical UICenterOnChild
« Reply #1 on: February 14, 2014, 05:35:40 AM »
That's a good point. I will add your code, thanks!

pigi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Horizontal drag triggers threshold on vertical UICenterOnChild
« Reply #2 on: February 14, 2014, 05:05:30 PM »
My pleasure! Please do keep in mind that I'm not sure about my implementation for Unrestricted and Custom, and I didn't actually test it. Just went with my instinct here.  ;D

Cheers!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Horizontal drag triggers threshold on vertical UICenterOnChild
« Reply #3 on: February 15, 2014, 01:34:29 AM »
Yeah it's fine.