Author Topic: I meet a bug with UIScrollView.  (Read 5331 times)

woshihuo12

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
I meet a bug with UIScrollView.
« on: November 13, 2014, 02:07:32 AM »
when i add UIScrollView use code like this:
  1.   mScrollView = mPanel.gameObject.AddComponent<UICustomScrollView>();
  2.            mScrollView.movement = UIScrollView.Movement.Vertical;
  3.            mScrollView.verticalScrollBar = scrollBar;
  4.  

i notice that in UIScrollView , when mPanel.gameObject.AddComponent<UICustomScrollView>() execute:
  1.         void OnEnable ()
  2.         {
  3.                 list.Add(this);
  4.  
  5.                 if (Application.isPlaying)
  6.                 {
  7.                         if (horizontalScrollBar != null)
  8.                         {
  9.                                 EventDelegate.Add(horizontalScrollBar.onChange, OnScrollBar);
  10.                                 horizontalScrollBar.alpha = ((showScrollBars == ShowCondition.Always) || shouldMoveHorizontally) ? 1f : 0f;
  11.                         }
  12.  
  13.                         if (verticalScrollBar != null)
  14.                         {
  15.                                 EventDelegate.Add(verticalScrollBar.onChange, OnScrollBar);
  16.                                 verticalScrollBar.alpha = ((showScrollBars == ShowCondition.Always) || shouldMoveVertically) ? 1f : 0f;
  17.                         }
  18.                 }
  19.         }

but when this the verticalScrollBar is null...

so i make a trick like this:
  1.         mScrollView = mPanel.gameObject.AddComponent<UICustomScrollView>();
  2.             mScrollView.movement = UIScrollView.Movement.Vertical;
  3.             mScrollView.verticalScrollBar = scrollBar;
  4.             [b]mScrollView.enabled = false;
  5.             mScrollView.enabled = true;[/b]
  6.  

so this a bug? can i have some help ??
very thanks...

woshihuo12

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: I meet a bug with UIScrollView.
« Reply #1 on: November 14, 2014, 01:33:18 AM »
someone can help me?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: I meet a bug with UIScrollView.
« Reply #2 on: November 14, 2014, 04:58:41 AM »
Replace the OnEnable() function with this code:
  1.         [System.NonSerialized] bool mStarted = false;
  2.  
  3.         void OnEnable ()
  4.         {
  5.                 list.Add(this);
  6.                 if (mStarted && Application.isPlaying) CheckScrollbars();
  7.         }
  8.  
  9.         void Start () { mStarted = true; if (Application.isPlaying) CheckScrollbars(); }
  10.  
  11.         void CheckScrollbars ()
  12.         {
  13.                 if (horizontalScrollBar != null)
  14.                 {
  15.                         EventDelegate.Add(horizontalScrollBar.onChange, OnScrollBar);
  16.                         horizontalScrollBar.alpha = ((showScrollBars == ShowCondition.Always) || shouldMoveHorizontally) ? 1f : 0f;
  17.                 }
  18.  
  19.                 if (verticalScrollBar != null)
  20.                 {
  21.                         EventDelegate.Add(verticalScrollBar.onChange, OnScrollBar);
  22.                         verticalScrollBar.alpha = ((showScrollBars == ShowCondition.Always) || shouldMoveVertically) ? 1f : 0f;
  23.                 }
  24.         }

woshihuo12

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: I meet a bug with UIScrollView.
« Reply #3 on: November 14, 2014, 06:17:10 AM »
thanks!!
can this changed in next ngui version?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: I meet a bug with UIScrollView.
« Reply #4 on: November 15, 2014, 04:12:37 PM »
This is from the latest Pro version, so yes.