Author Topic: UIScrollView  (Read 188624 times)

Jeff3po

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIScrollView
« Reply #45 on: April 01, 2014, 09:16:14 AM »
Is it possible to dynamically change the size of the Scroll View's UI Panel? I can GetViewSize() but can't figure out a way to alter it. I need the clipping frame to change dimensions based on how many objects are in my scroll list.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #46 on: April 01, 2014, 11:03:36 AM »
Yes, by adjusting UIPanel's baseClipRegion. Look at what happens in UIPanel.OnAnchor.

It's often easier to have the scroll view be anchored to a widget however (like a background widget) -- and then resize the widget. NGUIMath.ResizeWidget / NGUIMath.AdjustWidget via code, or UIDragResize -- the Endless Scroll Views example shows several resizeable scroll views in a single window.

JimBeard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIScrollView
« Reply #47 on: April 15, 2014, 09:39:40 AM »
Hi, I've got a ScrollView with a vertical scrollbar which is in a Resizable Panel. I have the ScrollBar set to show only when needed and it fades in and out nicely. But what I want to do is resize the ScrollView to fill that space when the scrollBar is hidden. Is there any way to get some kind of notification from UIScrollView when it does the show/hide? I've had a hunt but can't seem to find where it does it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #48 on: April 15, 2014, 10:27:13 AM »
Hmm, no there is no notification. I would advise looking at the code around line 836 of UIScrollView (in the LateUpdate function) where it will fade the scroll bars if they aren't needed. If you want some kind of a notification, it would have to go there.

Alternatively you can just watch the scroll bar's alpha from some script. When it's zero, resize the scroll view. When it's not zero, resize it the other way.

JimBeard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIScrollView
« Reply #49 on: April 15, 2014, 04:59:29 PM »
Thanks ArenMook that's what I was looking for.
I think I'll try the 'watching' option tho, as I'm still a bit new to the code side of things and I'm not sure of the best way to add to/extend your code without breaking things elsewhere.

I'd be happy to leave the scroll bar 'always on' but the behavior is kind of strange. The scroller (foreground) grows as expected when you enlarge the view and fills the bar completely when all items are in view, but if you keep enlarging the view it starts to shrink again, and if you drag it, the items scroll the other way.
I'd have expected the scroller to continue to grow with the panel and dragging it would have no effect as it has nowhere to move to, or anything to reveal. 'Cancel Drag if Fits' seems to have no effect on the scrollbars.

Great Tool BTW I'm learning a lot just from looking at how it all works.

JimBeard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIScrollView
« Reply #50 on: May 05, 2014, 01:46:58 PM »
Me again. I had the scroll view working nicely in nGUI 3.5.3 but I was setting the anchors to the left and right of the containing panel when I instantiated the items like this:

  1. GameObject item = NGUITools.AddChild( grid, itemPrefab );
  2. item.GetComponent<UISprite>().rightAnchor.target = scrollView.transform;
  3. item.GetComponent<UISprite>().leftAnchor.target = scrollView.transform;
  4. item.GetComponent<UIDragScrollView>().scrollView = scrollView.GetComponent<UIScrollView>();
  5. item.GetComponent<UIButton>().onClick.Add( new EventDelegate( this, "SelectItem" ));
  6.  
  7. grid.GetComponent<UIGrid>().Reposition();
  8. scrollView.GetComponent<UIScrollView>().UpdatePosition();
  9.  

That way when I dragged the scrollview out horizontally the items stretched with it but since i updated to nGUI 3.5.8 it no longer works, the items get squashed up to 2 pixels in the middle of the panel.

What am I doing wrong here? I want the items to fit the scrollview from edge to edge when it's resized horizontally.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #51 on: May 06, 2014, 12:05:59 AM »
Every time you change anchors you need to ResetAnchors() and UpdateAnchors(). Look at UIRect.SetAnchor functions. They do everything properly inside.

JimBeard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIScrollView
« Reply #52 on: May 06, 2014, 12:40:08 PM »
Thank you! That's fixed it.  :)

nzen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: UIScrollView
« Reply #53 on: May 12, 2014, 12:30:17 AM »
FIXED: Good ol' restarting Unity fixed it. Quoted for reference.
Quote
All my scrollview's children disappeared when Soft Clip/Alpha Clip was selected (editor mode and play mode). It was after saving a script then applying a prefab.

I updated to the latest version and now it shows children, but Soft Clip won't hide anything. The shader isn't cutting them off.

Is there a way to fix this?
« Last Edit: May 12, 2014, 01:08:03 AM by nzen »

pawankumar113

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UIScrollView
« Reply #54 on: May 14, 2014, 07:21:20 AM »
How access position of Clipping Rectangle

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #55 on: May 14, 2014, 07:24:17 AM »
If corners, then panel.localCorners or panel.worldCorners, depending on what you need. If actual modifiable position -- panel.clipOffset.

DL_Alex

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIScrollView
« Reply #56 on: May 15, 2014, 10:18:25 AM »
Hello,

I'm trying to setup a UIScrollView to work with a scroll bar, and for some reason it's not reacting in the way I need. I must be missing something.

Here's my heirarchy:
Panel
- ScrollView
- - Grid
- - - DragScrollView (x71)
- ScrollBar
- - Sprite (Foreground)
- - Sprite (Background)

When I drag on the DragScrollView items it works as intended, however, when I drag the foreground of the scrollbar it only moves the clipping of the scrollview instead of the clipping and the contents. How would I get the scrollbar to affect the scrollview like dragging the dragscrollview items?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #57 on: May 15, 2014, 12:15:07 PM »
I'm not sure what you've done there, but there are many examples in NGUI that use scroll bars + scroll views. 3.0.7 Tutorial video covers it also. I'm guessing you should be able to deduce the issue quite easily by having a look at either.

DL_Alex

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIScrollView
« Reply #58 on: May 15, 2014, 01:02:44 PM »
Hi Aren,

I've looked at the video you mentioned but it still hasn't helped me, in the video you aren't using a grid so it's a slightly different scenario. I'm noticing when I drag the gameObjects with a DragScrollView attached, the scroll view's transform and clip offset are modified, but when I use the scroll bar to control the up and down motion (this is a vertical scroll view) only the clip offset is affected, the scroll view's transform isn't affected. Is this intended? Is there a flag to set it so that the transform and the clipping both move while using the scroll bar as it does with the dragscrollview?

Thanks,
Alex.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #59 on: May 16, 2014, 03:00:53 PM »
No, you've missed something. Have you looked at Example 7 - Scroll View? It has a horizontal scroll view with a scroll bar.