Author Topic: UIScrollView onDragFinished not working  (Read 6590 times)

Eze

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
UIScrollView onDragFinished not working
« on: July 31, 2014, 06:13:47 PM »
Hi,

I'm trying to recieve an event from scroll view when it stops moving to get centeredObject from UICenterOnChild but onDragFinished is not getting called.

  1.         void OnEnable() {
  2.                 scrollView.onDragFinished += whichPageIsActive;
  3.         }
  4.  
  5.         public void whichPageIsActive() {
  6.                 if (currentPage.centeredObject == page1) {
  7.                         Debug.Log("Page 1");
  8.                 } else if (currentPage.centeredObject == page2) {
  9.                         Debug.Log("Page 2");
  10.                 }
  11.         }
  12.  

When I replace onDragFinished with onDragStarted it works fine. What am I missing here?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView onDragFinished not working
« Reply #1 on: August 01, 2014, 08:05:27 PM »
You should use "onStoppedMoving" instead. OnDragFinished is when you actually stop dragging -- it doesn't mean the movement has ceased.

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 62
    • View Profile
Re: UIScrollView onDragFinished not working
« Reply #2 on: October 17, 2014, 10:54:44 AM »
I'm also having this issue, I have onDragFinished set to a function that simply prints a message to Console and it never gets called, so its not an issue of which one I should be using but that it just never gets called ever.

I am doing a zoom out and back in effect when the user starts drag and ends drag so I really do need to know when the drag ends rather then when movement stops.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView onDragFinished not working
« Reply #3 on: October 18, 2014, 08:48:24 AM »
I'm guessing it's because you have UICenterOnChild there. I believe in the current Asset Store version of NGUI, it sets the callback rather than += appending it. Line 85 of UICenterOnChild. Change equals to +=. Same thing with the scroll bar callbacks directly below.

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 62
    • View Profile
Re: UIScrollView onDragFinished not working
« Reply #4 on: October 19, 2014, 08:57:08 PM »
That was indeed the problem, thanks!