Tasharen Entertainment Forum

Support => NGUI 3 Documentation => Topic started by: ArenMook on November 23, 2013, 08:49:55 AM

Title: UIScrollView
Post by: ArenMook on November 23, 2013, 08:49:55 AM
Overview

A clipped UIPanel (http://www.tasharen.com/forum/index.php?topic=6705) is not complete unless it can be dragged around like a scroll view, right? Right!

(http://www.tasharen.com/ngui/dragpanel.jpg)

Turning a panel into a Scroll View is a short 3-step process.

(http://www.tasharen.com/ngui/uidragscrollview.jpg)

Note that if you have more than one collider, then you will need to add Drag Scroll View script to all of them that the user will be able to press on. So for example if you have a scroll view like in the Scroll View Example where you have a background area and a bunch of items inside it, then you will want to add the UIDragScrollView to the background as well as each of the children. The idea behind it is simple: every collider that can intercept the event should be capable of dragging the scroll view.

Note that the context menu-based approach is context-sensitive. So if you right-click on a widget that doesn't have a collider, you won't be able to see the drag scroll view option.

(http://www.tasharen.com/ngui/uiscrollview.jpg)

On the scroll view script you have several options for you to tweak. First comes the Content Origin that's used to specify where the scroll view's content will originate.

Next comes the Movement that lets you choose whether you are making a Horizontal or a Vertical draggable panel. You can also choose Unrestricted movement which will let you drag the content around freely. If you want some custom movement, you can set the field to Custom and set your own X and Y values.

The Drag Effect option controls how the scroll view behaves when you drag it around. MomentumAndSpring is the default iOS-like behaviour.

If you want the scroll view to be scrollable with the mouse scroll wheel, play with the Scroll Wheel Factor value. Note that you can specify a negative value such as -0.25 if you want the mouse wheel scrolling to be inverted.

Momentum Amount controls how the scroll view behaves when the user lets go of the drag mid-swing (swiping gesture). Tweak this value to make it more or less sensitive based on what you desire.

In most cases you will want to have Restrict Within Panel option left turned on, as this is what will prevent your scroll view's content from leaving the scroll view's region. In case you haven't guessed it already, the dimensions of the scroll view's content should already be outlined by the orange color in the scene view.

Cancel Drag If Fits option will prevent the content from leaving the bounds at all. If left off, it will be possible to drag the content outside the bounds, but there will be visible resistance in doing so.

Smooth Drag Start and IOS Drag Emulation options further tweak the behaviour of the scroll view script, and in most cases you will just leave them at default values.

If you have a Horizontal or a Vertical Scroll Bar, you can specify them in the appropriate fields. Once done, you can also choose what happens to the scroll bars when they are not needed by adjusting the Show Scroll Bars option.

Limitation

In NGUI 3.5.5 and earlier versions, a scroll view will only clip the widgets directly underneath it. If you nest scroll views, the clipping will not be nested. Only one scroll view can clip the content inside of it. NGUI 3.5.6 lifts this limitation, provided you stick to using an NGUI's shader on your atlas such as Unlit - Transparent Colored.

Pro-Tip #1

It's best to leave the Scroll Bars Show Condition at OnlyIfNeeded so that your scroll bars will get automatically hidden until they are actually needed.

Pro-Tip #2

If you want to create an Endless Scroll View, attach a UIWrapContent script underneath it like so:

(http://www.tasharen.com/ngui/wrap.jpg)

Class Documentation

http://tasharen.com/ngui/docs/class_u_i_scroll_view.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.
Title: Re: UIScrollView
Post by: vexe on November 23, 2013, 12:00:59 PM
I can't believe my eyes, you really made a nice doc following my suggestion! You are the best developer ever! Thanks.

About the scroll view - I've always found it a bit inconvenient to have it scroll by left/right clicking and dragging. What if I only wanted it to drag when I hold right click and drag? and not left click? I would have to modify the code - which is not very nice since my changes will get overwritten in the next update.

Another thing, is that if one would specify unrestricted movement and scroll with the mouse - it would scroll diagonally! which is very odd, as a user I would expect that scrolling with the mouse, will only scroll vertically - While holding the middle mouse button and moving the mouse left/right would scroll horizontally.
Title: Re: UIScrollView
Post by: ArenMook on November 23, 2013, 12:39:02 PM
Unrestricted movement scroll with the mouse is only horizontal for me in 3.0.6. As for the mouse button other than left... you only need to create a custom UIDragScrollView script. Nothing else needs to change.
Title: Re: UIScrollView
Post by: PaulGregory on November 26, 2013, 05:39:56 AM
As discussed elsewhere (http://www.tasharen.com/forum/index.php?topic=6795.0), the context menu does not work for me and at least one other person (the only common denominator currently identified being that we're both on Mac).

So "Attach > Scroll View" is thus unavailable to me. Can you please confirm if adding the component Scroll View to the panel in the inspector (click Add Component, start typing scroll, pick Scroll View) completes step 1 or if the menu option sets anything else up?

Similarly for step 3, is it sufficient to (on the collider) click Add Component, start typing scroll, pick Drag Scroll View or is there something extra that would need to be done?

Shortcuts are great, but it's good to have what they actually do documented in case the shortcut can't be used (or indeed, for checking that everything is already set up correctly).
Title: Re: UIScrollView
Post by: ArenMook on November 26, 2013, 06:26:14 AM
That has been fixed. Just grab the latest (f3). :)
Title: Re: UIScrollView
Post by: Wumpee on December 03, 2013, 08:55:06 PM
Is UIDragScrollView supposed to be in 3.0.6f7?
Title: Re: UIScrollView
Post by: ArenMook on December 03, 2013, 09:02:19 PM
Yes, it's there. Make sure you're following NGUI's upgrade instructions that involve deleting the NGUI folder.
Title: Re: UIScrollView
Post by: Wumpee on December 03, 2013, 10:35:29 PM
Thanks. I didn't perform the NGUI update, but I'll follow up on that now.
Title: Re: UIScrollView
Post by: honeal on January 08, 2014, 08:26:52 PM
Maybe something wonky has occurred with my import, but it seems creating the scroll view via the toolbar does not include the UIScroll View script automatically. Creating it via the context menu does. Just an FYI.
Title: Re: UIScrollView
Post by: Oakshiro on January 10, 2014, 07:40:41 AM
Is there any easy way to make the UIScrollView go "page by page"?

I am trying to put a "next page" button, and everything goes ok until i reach the extens of the scroll, am I going ok doing this?


  1.         Vector3 targetPosition = scrollView.transform.localPosition;
  2.                 targetPosition.x += moveBy;
  3.  
  4.                 if (targetPosition.x < -scrollView.bounds.extents.x)
  5.                 {
  6.                         targetPosition.x = -scrollView.bounds.extents.x;
  7.                 }
  8.  
  9.                 SpringPanel.Begin (scrollView.gameObject, targetPosition, 13f);

THANKS!


It is NGUI 3, btw
Title: Re: UIScrollView
Post by: ArenMook on January 10, 2014, 09:18:59 AM
UICenterOnChild can be used to center on pages, and has an option to flick to go to the next page (the threshold, in pixels).
Title: Re: UIScrollView
Post by: Oakshiro on January 10, 2014, 10:42:16 AM
Hmmm, I can't see how UICenterOnChild could work for that... It just centers my first grid element on the center of the screen, and I only can change its spring strength...

What I intend to do is to have one button on each side of the scrollview and move one page left or right when I click on them, but keeping the content inside the bounds.


EDIT:
Ok, i see there is a CenterOn(Transform t) to center it on an object. The problem is my pages have 6 elements, so I should center it between two elements...
Title: Re: UIScrollView
Post by: ArenMook on January 10, 2014, 06:20:10 PM
Have a look at how it works in the Scroll View (Panel) example. UICenterOnChild centers on the child object whos transform's position is the closest to the center of the scroll view.

If you wanted to center in-between of elements, you would structure your content like so:

Center On Child
- Child 1
-- Element 1
-- Element 2
-- Element 3
-- Element 4
-- Element 5
-- Element 6
- Child 2
-- Element 1
-- Element 2
-- Element 3
-- Element 4
-- Element 5
-- Element 6
...etc

Center On Child will center on your "Child 1", "Child 2", etc, rather than "Element X"
Title: Re: UIScrollView
Post by: Oakshiro on January 10, 2014, 06:45:35 PM
That could have worked indeed, but in the end I created my own PageScrollView class, based on UICenterOnChild. It might not be the best code in the world, but hey, it works!
Thanks for your help :)

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. /// <summary>
  5. /// Attach this script to the container that has the objects to allow paging
  6. /// </summary>
  7.  
  8. public class PageScrollView : MonoBehaviour {
  9.  
  10.         public float springStrength = 8.0f;
  11.  
  12.         private UIScrollView scrollView;
  13.         private int elementsPerPage;
  14.         private int currentScrolledElements;
  15.         private Vector3 startingScrollPosition;
  16.  
  17.         private UIGrid grid;
  18.  
  19.         // Use this for initialization
  20.         void Start ()
  21.         {
  22.                 if (scrollView == null)
  23.                 {
  24.                         scrollView = NGUITools.FindInParents<UIScrollView>(gameObject);
  25.                         if (scrollView == null)
  26.                         {
  27.                                 Debug.LogWarning(GetType() + " requires " + typeof(UIScrollView) + " object in order to work", this);
  28.                                 enabled = false;
  29.                                 return;
  30.                         }
  31.  
  32.                         grid = this.GetComponent<UIGrid>();
  33.                         elementsPerPage = (int) (scrollView.panel.clipRange.z / grid.cellWidth);
  34.                         currentScrolledElements = 0;
  35.                         startingScrollPosition = scrollView.panel.cachedTransform.localPosition;
  36.                 }      
  37.         }
  38.        
  39.         // Update is called once per frame
  40.         void Update () {
  41.        
  42.         }
  43.        
  44.  
  45.         /// <summary>
  46.         /// Scrolls until target position matches target panelAnchorPosition (may be the center of the panel, one of its sides, etc)
  47.         /// </summary> 
  48.         void MoveBy (Vector3 target)
  49.         {
  50.                 if (scrollView != null && scrollView.panel != null)
  51.                 {
  52.                         // Spring the panel to this calculated position
  53.                         SpringPanel.Begin(scrollView.panel.cachedGameObject, startingScrollPosition - target, springStrength);
  54.                 }
  55.         }
  56.  
  57.  
  58.         public void NextPage()
  59.         {
  60.                 if (scrollView != null && scrollView.panel != null)
  61.                 {
  62.                         currentScrolledElements += elementsPerPage;
  63.                         if (currentScrolledElements > (this.transform.childCount - elementsPerPage))
  64.                         {
  65.                                 currentScrolledElements = (this.transform.childCount - elementsPerPage);
  66.                         }
  67.                         float nextScroll = grid.cellWidth * currentScrolledElements;
  68.                         Vector3 target = new Vector3(nextScroll, 0.0f, 0.0f);                          
  69.                         MoveBy(target);
  70.                 }
  71.         }
  72.  
  73.         public void PreviousPage()
  74.         {
  75.                 if (scrollView != null && scrollView.panel != null)
  76.                 {
  77.                         currentScrolledElements -= elementsPerPage;
  78.                         if (currentScrolledElements < 0)
  79.                         {
  80.                                 currentScrolledElements = 0;
  81.                         }
  82.                         float nextScroll = grid.cellWidth * currentScrolledElements;
  83.                         Vector3 target = new Vector3(nextScroll, 0.0f, 0.0f);                          
  84.                         MoveBy(target);
  85.                 }
  86.         }
  87.  
  88. }
  89.  
Title: Re: UIScrollView
Post by: nerophon on January 16, 2014, 12:46:39 PM
Hi,

We love the CenterOnChild behavior and are using it to tween our scrollView. Sadly, however, if a user taps / clicks during the tween, the tween is canceled (or overridden?) and the scrollView stops where it is. It does not even snap back to the nearest child.

How can we prevent this behavior? We want the scrollView to NOT stop tweening due to a user press, but a user swipe should still override it with a new tween in the new swipe direction.

Many thanks!

Nick
Title: Re: UIScrollView
Post by: ArenMook on January 17, 2014, 12:35:20 AM
I think this will already be fixed in the next release. Bump it if not.
Title: Re: UIScrollView
Post by: CBYum on January 20, 2014, 07:20:00 AM
I'm using a ScrollView to scroll a Grid that uses CenterOnChild to lock each element (is a vertical list of numbers). I'm trying to default it to point to different entries when it's shown but am struggling. I need to place it at element N in the grid. The only way to move it at all seemed to be with CenterOn but this doesn't seem to have an option to snap to an entry and so it slides even if I set a stupidly high strength. It also requires that I have the transform of the target entry but I only know the index at the moment (and Grid doesn't keep a list).

What way should I be using to achieve this?

Thanks
Title: Re: UIScrollView
Post by: ArenMook on January 20, 2014, 07:36:56 AM
UICenterOnClick is a useful script to look at. It will use UICenterOnChild if present, or simply SpringPanel to the target position if not. I'd recommend using that as a starting point.
Title: Re: UIScrollView
Post by: AbsurdInteractive on January 24, 2014, 08:00:10 PM
We've setup a Vertical ScrollView as mentioned, but our paging doesn't really seem to work. We have two grids of 12 UIButtons each parented under the ScrollView.

The layout is like this:

Container
|-- ScrollView
     |-- Grid
          |-- UIButtons x 12
     |-- Grid
          |-- UIButtons x 12

If you swipe upwards really fast it will pop to the next "page" grid, but if you click and drag upwards the paging will not happen and the scrollview will stop in-between the 2 pages, which is undesirable. Is there a way to make sure that no matter whether the player wipes or drags that the scrollview will pop to the closets page?
Title: Re: UIScrollView
Post by: ArenMook on January 25, 2014, 02:42:29 AM
Yes, by using UICenterOnChild. Place it on the same object as your Scroll View. It will use the children's positions to determine what's closer (in your case -- Grid objects). So I suggest you make sure that the positions are centered. I wouldn't use UIGrid in your case as it's always top-left based instead.
Title: Re: UIScrollView
Post by: AbsurdInteractive on January 25, 2014, 06:29:17 PM
We were using UIGrid so that out level buttons were nicely placed in nice and neat 3x4 fashion for each page.

Is there a way to make the UIGrid not top-left based? If not is there an alternative to keeping UIButtons nicely grid like, but with center based?
Title: Re: UIScrollView
Post by: ArenMook on January 25, 2014, 06:42:08 PM
I'm going to change the UIGrid to make it possible to change the pivot in a future update. Right now it's always top-left. You can edit it to support other methods if you like, or just create a simple positioning script yourself to do that. transform.childCount gives you the number of children. Knowing that you want certain number of columns, iterating through the children via transform.GetChild(i) and changing its localPosition is a trivial matter. Afterwards, offset the grid object's position by number of columns * 0.5 * cell width.
Title: Re: UIScrollView
Post by: NGUIJeffS on February 01, 2014, 05:08:10 PM
Hello, I've looked through the docs for an answer to this question but have found nothing or I've overlook it. My question is, Is there a way to restrict the mouse "grabbing"/dragging of scroll items to only occur within the visible portion of a scroll window?

That is, I have a simple scroll window as shown in the latest 3.0.7 tutorial with 12 items in the scroll window, but only 2 items are seen (are showing) in the visible area of the window at any given time. It's an Hz scroll window. Everything works fine (HZ scrolls nicely) with the exception that if I place the mouse just outside of the scroll windows visible area I'm able to drag items not shown in the window into the window. Is that right? I would expect that only the items visible in the window would react to the mouse grab and drag. Am I doing something wrong? Is there a setting I'm missing that would limit mouse drag to only occur for items in the window? or is this just the way it works? Hope I'm making sense.
Title: Re: UIScrollView
Post by: ArenMook on February 01, 2014, 07:01:36 PM
NGUI events are always clipped by the scroll view's region if the UICamera is set to "UI" mode. If it's set to "World", then they aren't.
Title: Re: UIScrollView
Post by: NGUIJeffS on February 01, 2014, 07:13:17 PM
Yes, My UICamera (script) Event Type was set to World. I changed it to UI and all works well and it makes sense. Excellent! After building and rebuilding my scroll windows several times I thought it had to be something simple. Thanks so much!
Title: Re: UIScrollView
Post by: monogon on February 26, 2014, 03:53:25 PM
Hey ArenMook,
I'm trying to utilize UIScrollview to build a little button press game.
The first button in the scrollview is supposed to be the current button that the player has to press.
When he hits the right button, I want this sprite to "dequeue" from scrollview (as if dragged out of scrollView manually) and the other sprites to move up to the current position within UIGrid (smoothly). Then I want a new button to be created at the end of the scrollview grid. For dragging the sprite out of the scrollview and vanishing I thought of an invisible second panel with a box collider.
I followed your tutorial, UIGrid with Scrollview and dragging is working fine but now I need to know how to access the 'dequeuing'/dragging out of scrollview from script.
Do you think there is a way to use UIScrollview this way? Or am I on the wrong track!

Btw awesome tool. I bought your plugin last week and am very pleased so far!

Thanks in advance!

Regards! monogon
Title: Re: UIScrollView
Post by: ArenMook on February 26, 2014, 03:55:10 PM
Have you seen the Drag & Drop example that comes with NGUI? It does just that.
Title: Re: UIScrollView
Post by: monogon on February 26, 2014, 08:28:58 PM
Thank you!

I know created a class inherited from UIDragDropItem that serves its purpose.

On start I create an array of 10 int values which I then fill with random values between 1 and 5. Now I have a script in my scrollView that grabs this array and instantiates icons for every value in the array as a child of the Grid-Object in the scrollview. '1' results in an instance of iconButton1, '2' in an instance of iconButton2 and so on.

The instantiation works fine and the icons are sorted within the grid (each button has a offset of 75px). However, the instances are created with a z-value of 5400 and a uniform scale of 360 each, although the prefab has the position (0,0,0) and the scale (1,1,1). Do you know what goes wrong during the instantiation process?

I now adjusted the values manually after instantiation but I'm very curious to find the reason for this bug.
Title: Re: UIScrollView
Post by: ArenMook on February 27, 2014, 06:48:27 PM
You need to use NGUITools.AddChild(parent, prefab) to instantiate objects. It sets the parent, scale, and layer properly all in one function.
Title: Re: UIScrollView
Post by: RelayOne on March 05, 2014, 11:24:36 AM
I just upgrade NGUI, and am in the process of upgrading UIDraggablePanel to UIScrollView. My UIDraggablePanel components were reporting missing scripts. I tried to create new UIScrollView using "Add Component", but it was missing from the menu.

I renamed the .cs file from UIDraggablePanel.cs to UIScrollView.cs, and all of a sudden everything worked.

I also had to rename UICheckbox.cs to UIToggle.cs, and that also made everything work.

I'm running Unity 4.3.1f on a Macbook Air with Mavericks. I'm also using Editor Settings -> version control -> Mode -> Visible Meta Files.
Title: Re: UIScrollView
Post by: ArenMook on March 06, 2014, 12:13:54 PM
You won't need to rename anything if you follow the 3-step upgrade instructions from the readme file.
Title: Re: UIScrollView
Post by: nzen on March 07, 2014, 09:31:51 AM
I solved this as I was writing, but I will put it here for others Google searching (Solution: use scrollView.ResetPosition() (http://tasharen.com/ngui/docs/class_u_i_scroll_view.html#ac4fbddd1de781f66473614694ea78a91) after instantiating content);
Quote
I have an issue where I instantiate some buttons inside a Scroll View (NGUITools.AddChild), but when scrolling with the mousewheel, they won't restrict within the panel.

When moving the mousewheel up, the content will slide off the bottom of the Scroll View. When moving the mousewheel up, it will restrict, but the origin seems off, so it's not aligning with the bottom of the content.

While playing, it auto-fixes when left-clicking to drag. I can also fix it while playing by changing Content Origin in the inspector to anything, and when changing it back, it will also remain fixed. No matter what the Content Origin is when playing, it doesn't work.
Title: Re: UIScrollView
Post by: Wumpee on March 12, 2014, 05:09:49 AM
Hi,

How should I clamp the horizontal movement of a scroll view? in previous updates I was able to use a separate script to clamp the scroll view's transform on the X axis, but doing that doesn't work any longer.

All I am wanting to do is have a map with markers on it, and have it so that the map always stays within the scroll view
Title: Re: UIScrollView
Post by: ArenMook on March 12, 2014, 06:09:53 PM
Scroll view is moved by adjusting the UIPanel.clipOffset, so you will want to adjust that instead.
Title: Re: UIScrollView
Post by: Wumpee on March 12, 2014, 11:20:22 PM
Thanks ArenMook, I've tried adjusting UIPanel.clipOffset too, but it appears to have the same issue.

e.g. if I run the following code in the Update or LateUpdate of a separate script which is attached to the same game object as the UIPanel, it behaves strangely, snapping the scroll view to the wrong position once you get past minX or maxX

  1.         Vector2 pos = panel.clipOffset;
  2.         pos.x = Mathf.Clamp(pos.x, minX, maxX);
  3.         panel.clipOffset = pos;
  4.  
Title: Re: UIScrollView
Post by: ArenMook on March 13, 2014, 12:32:09 AM
Have a look inside SpringPanel script. It does the panel movement logic inside. As you adjust the clipOffset you also need to adjust the localPosition by the opposite value.
  1.         Vector3 before = mTrans.localPosition;
  2.                 Vector3 after = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta);
  3.                 mTrans.localPosition = after;
  4.  
  5.                 Vector3 offset = after - before;
  6.                 Vector2 cr = mPanel.clipOffset;
  7.                 cr.x -= offset.x;
  8.                 cr.y -= offset.y;
  9.                 mPanel.clipOffset = cr;
Title: Re: UIScrollView
Post by: Wumpee on March 13, 2014, 02:38:59 AM
Thanks for that ArenMook, I've adapted that to work fine.
Title: Re: UIScrollView
Post by: AbsurdInteractive on March 19, 2014, 07:17:04 PM
Our ScrollView seemed to be working properly until we updated to the latest version of NGUI from the Asset store just today.

When the scene would start our scrollview would be in the correct position, but now when the scene starts it moves downwards with some motion a little bit which now offsets all of our buttons. I was wondering if you might have any suggestions on what we should look at to fix this?

Before:
http://imgur.com/wTsQXFH,ARA9bJz#1

After:
http://imgur.com/wTsQXFH,ARA9bJz#0
Title: Re: UIScrollView
Post by: ArenMook on March 20, 2014, 02:30:16 AM
What does it look like in inspector, and what else do you have in the scroll view aside from those number buttons? Also, what's the Origin Point on the scroll view?
Title: Re: UIScrollView
Post by: AbsurdInteractive on March 20, 2014, 06:19:46 PM
In the inspector, before I play the scene, everything looks correctly positioned.

Here's my NGUI hierarchy:

Container
|-- ScrollView
     |-- Grid
          |-- UIButtons x 9
               |-- UILabel child in each UIbutton
     |-- Grid
          |-- UIButtons x 9
               |-- UILabel child in each UIbutton


My Content Origin is Top.

EDIT:
Ok, so I have a UICenterOnChild script attached to my scrollview gameobject. When I set the Spring Strength to 0 in the UICenterOnChild component and play the scene the buttons show up correctly in the right position.

The problem though is I really need the Spring Strength for paging. I had it set to 8. Is there a way to just tell it to not use SpringStrength on Start, but only when the user touches/clicks the scrollview? I might add I'm not 100% sure the Spring Strength is the issue though.
Title: Re: UIScrollView
Post by: ArenMook on March 21, 2014, 04:21:33 PM
Why do you have two grids? I'm not sure I quite get your hierarchy. I would expect to see:

Container
- Scroll View
-- Grid (UICenterOnChild)
--- Buttons (x9)
---- Label

If going with a multi-page approach, I would expect to see:

Container
- Scroll View
-- Content (UICenterOnChild, maybe UIGrid)
--- Page 1 (UIGrid)
---- Button (x9)
--- Page 2 (UIGrid)
---- Button (x9)

Assuming each Page object is offset to be the center of the content under it, it will work as expected.
Title: Re: UIScrollView
Post by: AbsurdInteractive on March 21, 2014, 06:26:30 PM
I thought I remember you mentioning earlier that we should have the UICenterOnChild script on the UIScrollView gameObject?

I have two grids as each grid is a set of 9 buttons which makes a page for us. I'll try the layout you suggested. It's weird that it was working before the update.
Title: Re: UIScrollView
Post by: AbsurdInteractive on March 21, 2014, 06:35:10 PM
I looked back through this thread and found this conversation between us:

ArenMook:
Place UICenterOnChild on the same object as your Scroll View. It will use the children's positions to determine what's closer (in your case -- Grid objects). So I suggest you make sure that the positions are centered. I wouldn't use UIGrid in your case as it's always top-left based instead.

AbsurdInteractive:
We were using UIGrid so that out level buttons were nicely placed in nice and neat 3x4 fashion for each page.
Is there a way to make the UIGrid not top-left based? If not is there an alternative to keeping UIButtons nicely grid like, but with center based?

ArenMook:
I'm going to change the UIGrid to make it possible to change the pivot in a future update. Right now it's always top-left. You can edit it to support other methods if you like, or just create a simple positioning script yourself to do that. transform.childCount gives you the number of children. Knowing that you want certain number of columns, iterating through the children via transform.GetChild(i) and changing its localPosition is a trivial matter. Afterwards, offset the grid object's position by number of columns * 0.5 * cell width.



Did you change how the UICenterOnChild works in the update since? Did I guess my problem is perhaps the custom pivot code I wrote got wiped out in the update? Or does UIGrid support custom pivot points now?
Title: Re: UIScrollView
Post by: ArenMook on March 22, 2014, 09:21:10 PM
UICenterOnChild hasn't changed recently. UIGrid has a Pivot point in 3.5.5.
Title: Re: UIScrollView
Post by: AbsurdInteractive on March 23, 2014, 02:22:32 PM
It looks like 3.5.5's Grid Pivot Point option fixed everything. :) Thanks.
Title: Re: UIScrollView
Post by: Jeff3po 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.
Title: Re: UIScrollView
Post by: ArenMook 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.
Title: Re: UIScrollView
Post by: JimBeard 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?
Title: Re: UIScrollView
Post by: ArenMook 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.
Title: Re: UIScrollView
Post by: JimBeard 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.
Title: Re: UIScrollView
Post by: JimBeard 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.
Title: Re: UIScrollView
Post by: ArenMook 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.
Title: Re: UIScrollView
Post by: JimBeard on May 06, 2014, 12:40:08 PM
Thank you! That's fixed it.  :)
Title: Re: UIScrollView
Post by: nzen 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?
Title: Re: UIScrollView
Post by: pawankumar113 on May 14, 2014, 07:21:20 AM
How access position of Clipping Rectangle
Title: Re: UIScrollView
Post by: ArenMook 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.
Title: Re: UIScrollView
Post by: DL_Alex 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?
Title: Re: UIScrollView
Post by: ArenMook 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.
Title: Re: UIScrollView
Post by: DL_Alex 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.
Title: Re: UIScrollView
Post by: ArenMook 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.
Title: Re: UIScrollView
Post by: davitosan on June 03, 2014, 03:46:52 PM
Hello,

I've implemented the UIScrollView using Example 7 Scroll View (Panel) as a reference. Works as I need, thank you very much.

In your example you are emulating a shop where a user can select and purchase items.

My question is, is it be possible to maintain the scroll functionality as is but limit the area that would purchase the item? Adding a buy now button below the gold price per item to where clicking the button and only the buttons executes some method. But dragging anywhere including the button scrolls the view.

If case my question/description isn't clear enough. The only thing that I can think of that is similar is Farm Heroes (mobile) Leaderboard. I cannot find any video of anyone actually doing this though.
Title: Re: UIScrollView
Post by: davitosan on June 03, 2014, 04:03:23 PM
Hello,

I've implemented the UIScrollView using Example 7 Scroll View (Panel) as a reference. Works as I need, thank you very much.

In your example you are emulating a shop where a user can select and purchase items.

My question is, is it be possible to maintain the scroll functionality as is but limit the area that would purchase the item? Adding a buy now button below the gold price per item to where clicking the button and only the buttons executes some method. But dragging anywhere including the button scrolls the view.

If case my question/description isn't clear enough. The only thing that I can think of that is similar is Farm Heroes (mobile) Leaderboard. I cannot find any video of anyone actually doing this though.

I figured it out. I guess I just needed to write it out. Here is my solution

Panel
- Scroll View
- - Grid
- - - Item
- - - - Button
- - - Item
- - - - Button

The button contains a collider and a UIForward Events script. I forward the Events to the Item (Buttons Parent).
Title: Re: UIScrollView
Post by: PoN on June 05, 2014, 09:59:50 PM
Hi Aren, I would use endless scroll view with my data , which in List or Array, so i init each Item in endless scroll view in the UpdateItem(..) method, then when my last item data inited i would like to stop(lock) scroll possibility and when i scrolling to back that start(unlock) scroll possibility until first item data of List or Array data, it's like endless scroll view with a bounds . How can i do that ? can you help me ?

thanks
Title: Re: UIScrollView
Post by: balzaque on June 05, 2014, 11:01:36 PM
Hi, I have a scrollview that I need to dynamically change the content size and only show the scrollbars when the content gets big enough, I managed to do that by dynamically changing the height of a child widget.

When it grows bigger the scrollbars show without a problem but when i shrink the widget back the scrollbars stays there till I make a new action or click on something.

  1. container.height = 500;
  2. scrollView.ResetPosition();
  3. scrollBar.value = 0;
  4.  

This is how I'm currently trying to achieve this, not sure what I'm doing wrong. Without reseting both the scrollview and the scrollbar I was getting wrong positions since the scrollview was trying to keep aligned with my first button instead of going back to the start position.

Thanks! =]
Title: Re: UIScrollView
Post by: ArenMook on June 06, 2014, 02:51:27 AM
@PoN: If an endless scroll view has bounds, then it's not an endless scroll view anymore. It's just a regular scroll view.

@balzaque: You need to do what UITable does when repositioning its content within a scroll view. Namely calling UIPanel's ConstraintTargetToBounds, then updating the scroll bars. Check UITable's Reposition() function, line 229:
  1.                 if (keepWithinPanel && mPanel != null)
  2.                 {
  3.                         mPanel.ConstrainTargetToBounds(myTrans, true);
  4.                         UIScrollView sv = mPanel.GetComponent<UIScrollView>();
  5.                         if (sv != null) sv.UpdateScrollbars(true);
  6.                 }
Title: Re: UIScrollView
Post by: balzaque on June 06, 2014, 08:55:44 AM
Thanks, this is better then the way I was doing it.

I was also setting it at the same time I was starting a tween, had to make sure to call that after the tween had finished.
Title: Re: UIScrollView
Post by: AbsurdInteractive on June 06, 2014, 07:31:06 PM
I the latest update my ScrollView is fine in the editor when not in play mode. Once I enter play mode though, on the Awake method something is happening that causes my ScrollView buttons to move downwards slightly then move back up to their correct position. It seems to be awake and not enable because when I deactivate and then activate the UIRoot, it does not do that again. Do you have any suggestions to correct this issue?
Title: Re: UIScrollView
Post by: ArenMook on June 06, 2014, 10:06:45 PM
Awake() should be used for initializing script's local values. It should never be used for modification of other scripts or their values.
Title: Re: UIScrollView
Post by: AbsurdInteractive on June 07, 2014, 12:18:27 AM
Awake() should be used for initializing script's local values. It should never be used for modification of other scripts or their values.

Sorry, I should have been more specific. I don't call any Awake code or do anything special in my script that touches the UI. I just meant since, I've updated to 3.6.1, and 3.6.2, the UIScrollView I setup started to do the behavior I mentioned. I thought it might have to do with changes that were made in the Awake or Start of the NGUI UIScrollview script in v3.6.1.

Is there any code I can call to force the UIScrollview not to move when my scene starts?
Title: Re: UIScrollView
Post by: ArenMook on June 07, 2014, 09:33:36 PM
Alright, then I'm not quite sure I understand what's happening. Make sure to right-click on the scroll view and choose "Reset Clipping Position" so that the content is positioned properly. Also -- choose the desired Content Origin setting.
Title: Re: UIScrollView
Post by: AbsurdInteractive on June 10, 2014, 02:59:05 AM
The issue I'm having looks like it involves UICenterOnChild. The issue seems to be that the center child is not exactly in the center of my scroll view, and it seems when it executes for the first time in Play Mode this causes the content of my ScrollView to snap to the center causing the movement. I know I can manually try to drag the content to the center in the editor, but this seems like it could be a lot of guess and check work with all the different scenes I have with ScrollViews and CenterOnChild. Would it be possible to have UICenterOnChild be able to Execute the script in the Editor when not in Play Mode (similar to how UIGrid's right click Execute Script works), so that we can just execute the script and then save the scene to have everything automatically aligned?
Title: Re: UIScrollView
Post by: ArenMook on June 10, 2014, 03:11:14 AM
Sure thing. Just add "[ContextMenu("Execute")]" above the UICenterOnChild's Recenter() function.

Edit: You will also need to change the UICenterOnChild's CenterOn function to this:
  1.         void CenterOn (Transform target, Vector3 panelCenter)
  2.         {
  3.                 if (target != null && mScrollView != null && mScrollView.panel != null)
  4.                 {
  5.                         Transform panelTrans = mScrollView.panel.cachedTransform;
  6.                         mCenteredObject = target.gameObject;
  7.  
  8.                         // Figure out the difference between the chosen child and the panel's center in local coordinates
  9.                         Vector3 cp = panelTrans.InverseTransformPoint(target.position);
  10.                         Vector3 cc = panelTrans.InverseTransformPoint(panelCenter);
  11.                         Vector3 localOffset = cp - cc;
  12.  
  13.                         // Offset shouldn't occur if blocked
  14.                         if (!mScrollView.canMoveHorizontally) localOffset.x = 0f;
  15.                         if (!mScrollView.canMoveVertically) localOffset.y = 0f;
  16.                         localOffset.z = 0f;
  17.  
  18.                         // Spring the panel to this calculated position
  19. #if UNITY_EDITOR
  20.                         if (!Application.isPlaying)
  21.                         {
  22.                                 panelTrans.localPosition = panelTrans.localPosition - localOffset;
  23.  
  24.                                 Vector4 co = mScrollView.panel.clipOffset;
  25.                                 co.x += localOffset.x;
  26.                                 co.y += localOffset.y;
  27.                                 mScrollView.panel.clipOffset = co;
  28.                         }
  29.                         else
  30. #endif
  31.                         SpringPanel.Begin(mScrollView.panel.cachedGameObject,
  32.                                 panelTrans.localPosition - localOffset, springStrength).onFinished = onFinished;
  33.                 }
  34.                 else mCenteredObject = null;
  35.         }
Title: Re: UIScrollView
Post by: justkevin on June 12, 2014, 03:11:32 PM
I'm trying to reset the scroll view to the upper left corner after populating it. Calling ResetPosition() before and after I add elements doesn't seem to work.

As a test, I added ResetPosition to the Update() function, and that got it to reset correctly, but obviously I don't want to call it there.

Here's the class that does the layout:

  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. public class ResearchWindow : MonoBehaviour {
  5.     // Contains all our tech tree data:
  6.     public TechTreeManager techTree;
  7.  
  8.     // Each row of this will be a tech lineage:
  9.     public GameObject techLineageTable;
  10.     // The prefab we use for each tech node displayed in the tree:
  11.     public GameObject techButtonPrefab;
  12.  
  13.     // Various UI labels:
  14.     public UILabel researchPoints;
  15.     public UILabel techLabel;
  16.     public UILabel techDescription;
  17.     public UILabel techCost;
  18.  
  19.     private TechNode _activeNode;
  20.  
  21.     /**
  22.      * Set the active node details:
  23.      **/
  24.     public TechNode ActiveNode
  25.     {
  26.         get
  27.         {
  28.             return _activeNode;
  29.         }
  30.         set
  31.         {
  32.             _activeNode = value;
  33.             if (value != null)
  34.             {
  35.                 if (techLabel != null)
  36.                 {
  37.                     techLabel.text = _activeNode.name;
  38.                     techDescription.text = _activeNode.description;
  39.                     techCost.text = "Cost: " + _activeNode.researchPoints + " RP";
  40.                 }
  41.             }
  42.            
  43.         }
  44.     }
  45.  
  46.         void Start () {
  47.         DrawTechTree();
  48.         researchPoints.text = "You have " + GameManager.Instance.player.researchPoints + " Research Points";
  49.         }
  50.        
  51.         // Update is called once per frame
  52.         void Update () {
  53.         // This actually DOES reset the position how we want, but we don't want it here:
  54.         //UIScrollView scrollView = GetComponentInChildren<UIScrollView>();
  55.         //scrollView.ResetPosition();
  56.        
  57.         }
  58.  
  59.     /**
  60.      * Adds the individual lineage tables to the overall tech tree table, and the individual
  61.      * node buttons to each of those linage tables.
  62.      **/
  63.     private void DrawTechTree()
  64.     {
  65.         // Get the scrollview:
  66.         UIScrollView scrollView = GetComponentInChildren<UIScrollView>();
  67.         scrollView.ResetPosition();
  68.         // Get a list of all lineages:
  69.         List<string> lineageIds = techTree.GetLineageIds();
  70.         foreach (string id in lineageIds)
  71.         {
  72.             TechLineage lineage = techTree.GetLineage(id);
  73.             // Create a UITable for this lineage row:
  74.             GameObject lineageRow = NGUITools.AddChild(techLineageTable);
  75.             UITable rowTable = lineageRow.AddComponent<UITable>();
  76.             // For each node in the linage, add a button for it:
  77.             foreach (TechNode node in lineage.nodes)
  78.             {
  79.                 GameObject nodeButton = NGUITools.AddChild(lineageRow, techButtonPrefab);
  80.                 TechNodeButton techNodeButton = nodeButton.GetComponent<TechNodeButton>();
  81.                 techNodeButton.Node = node;
  82.                 techNodeButton.researchWindow = this;
  83.             }
  84.             rowTable.Reposition();
  85.         }
  86.         // This does nothing:
  87.         scrollView.ResetPosition();
  88.  
  89.     }
  90. }
  91.  
  92.  

Any suggestions what I might be doing wrong?

Title: Re: UIScrollView
Post by: RDeluxe on June 12, 2014, 05:52:08 PM
I'm trying to reset the scroll view to the upper left corner after populating it. Calling ResetPosition() before and after I add elements doesn't seem to work.

As a test, I added ResetPosition to the Update() function, and that got it to reset correctly, but obviously I don't want to call it there.

[...]


I have the exact same problem with a scrollview containing a UIGrid. When the resolution of the screen changes, I resize my grid, and then i call ResetPosition(). It's working well if I go from a 4/3 resolution to a 16/10, but in the opposite case I have a gap between the top of my grid and the top of my scrollview.
If I put ResetPosition() in the Update() method, it's working perfectly. But, to quote justkevin, "I don't want to do that"
Title: Re: UIScrollView
Post by: ArenMook on June 13, 2014, 06:20:58 AM
If you want it to execute once, and you know it works in the Update, then what I'd do is add a flag to your script, such as "bool mReset = false;" that I would set to 'true' in that script's OnEnable() function. In the Update I'd check to see if the flag is 'true', and if so -- ResetPosition().

Same can likely be done by using a co-routine, eliminating the need for 'mReset'.
Title: Re: UIScrollView
Post by: justkevin on June 13, 2014, 10:11:56 AM
Thanks for the response.

Unfortunately, that doesn't work-- calling ResetPosition for the first Update moves the scrollview, but not to the origin. Calling it for the first 2-3 updates causes it to disappear completely for some reason. Only after calling it for 4 consecutive updates gets it to the origin:

  1.         if (_resetAttempts < 4)
  2.         {
  3.             UIScrollView scrollView = GetComponentInChildren<UIScrollView>();
  4.             scrollView.ResetPosition();
  5.             ++_resetAttempts;
  6.         }
  7.  

That works, but I'm concerned that without understanding why 4 is the magic number of updates it may break with some change to the contents of the scrollview.

Using a delayed coroutine didn't work. Changing timescale had no effect.
Title: Re: UIScrollView
Post by: ArenMook on June 15, 2014, 06:13:07 AM
That doesn't make much sense to me. Might be something related to what else you're doing in there...
Title: Re: UIScrollView
Post by: RDeluxe on June 16, 2014, 08:40:22 AM
Well, here is my code.

I'm actually not doing anything fancy.

  1. public class PlacesScreen : MonoBehaviour
  2. {
  3.     // Used to check if the screen resolution changed
  4.     // TODO : Find a better solution than this one
  5.     public float startWidth;
  6.     public float startHeight;
  7.  
  8.     List<Place> places;
  9.     UIScrollView PlacesList;
  10.     UIGrid PlacesGrid;
  11.     GameObject FileList;
  12.  
  13.     // Hardcoded for testing purposes only
  14.     string json = @"[{ blabla
  15. }]";
  16.  
  17.     // Use this for initialization
  18.     void Start()
  19.     {
  20.         places = JsonConvert.DeserializeObject<List<Place>>(json);
  21.         PlacesList = gameObject.GetComponentInChildren<UIScrollView>() as UIScrollView;
  22.         PlacesGrid = gameObject.GetComponentInChildren<UIGrid>() as UIGrid;
  23.         FileList = GameObject.Find("Grid");
  24.  
  25.         startHeight = PlacesList.gameObject.GetComponent<UIPanel>().height;
  26.         startWidth = PlacesList.gameObject.GetComponent<UIPanel>().width;
  27.  
  28.         if (PlacesGrid != null && FileList != null && PlacesList != null)
  29.         {
  30.             BetterList<Transform> childList = PlacesGrid.GetChildList();
  31.  
  32.             // Addind the places from the json to the graphic list
  33.             foreach (Place place in places)
  34.             {
  35.                 Debug.Log("Adding a place");
  36.                 GameObject placeFile = Resources.Load("prefabs/File") as GameObject;
  37.                 placeFile.GetComponent<UISprite>().width = (int)PlacesGrid.cellWidth;
  38.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("PlaceName").gameObject.GetComponent<UILabel>().text = place.Name;
  39.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("CityName").gameObject.GetComponent<UILabel>().text = place.City;
  40.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("TypeName").gameObject.GetComponent<UILabel>().text = place.Type;
  41.                 NGUITools.AddChild(FileList, placeFile);
  42.                 childList.Add(placeFile.transform);
  43.             }
  44.  
  45.             // Small hack to get a nicely presented Grid even with only 1 element
  46.             // TODO : Redo this ...
  47.             if (childList.size == 1)
  48.             {
  49.                 Debug.Log("One place only, we have to had a invisible file to avoid center");
  50.                 GameObject invisibleFile = Resources.Load("prefabs/File") as GameObject;
  51.                 NGUITools.AddChild(FileList, invisibleFile);
  52.                 childList.Add(invisibleFile.transform);
  53.             }
  54.             ResizeGrid();
  55.         }
  56.     }
  57.  
  58.     // Update is called once per frame
  59.     void Update()
  60.     {
  61.         if (startHeight != PlacesList.gameObject.GetComponent<UIPanel>().height || startWidth != PlacesList.gameObject.GetComponent<UIPanel>().width)
  62.         {
  63.             ResizeGrid();
  64.             startHeight = PlacesList.gameObject.GetComponent<UIPanel>().height;
  65.             startWidth = PlacesList.gameObject.GetComponent<UIPanel>().width;
  66.         }
  67.     }
  68.  
  69.     /// <summary>
  70.     /// Resize the grid considering the screen width
  71.     /// </summary>
  72.     void ResizeGrid()
  73.     {
  74.         Debug.Log("ResizeGrid Called");
  75.         // Resizing the Grid cells' size.
  76.         PlacesGrid.cellWidth = (float)(PlacesList.gameObject.GetComponent<UIPanel>().width / 2.2);
  77.         PlacesGrid.cellHeight = (float)(PlacesGrid.cellWidth / 1.244);
  78.         foreach (Transform place in PlacesGrid.GetChildList())
  79.         {
  80.             place.gameObject.GetComponent<UISprite>().width = (int)PlacesGrid.cellWidth;
  81.         }
  82.         PlacesGrid.Reposition();
  83.         PlacesList.ResetPosition();
  84.     }
  85. }

The Resize() method is working perfectly well, resizing my elements. But when I'm coming from a wider resolution, here is what happen :

(http://i.imgur.com/uw6x21X.png)

Title: Re: UIScrollView
Post by: kennethljj on June 30, 2014, 12:27:12 AM
Hi Aren,

I have just recently upgraded from version 2+ and I got a question regarding the limitations of the UIScrollView.
From what I can remember, in version 2+, UIDraggablePanel have a limitation on the parents' scale. If any of the parents' scale (throughout hierarchy) is not the same (eg. 1f, 0.9f, 1f), the scrolling would have a problem.

Does UIScrollView have this limitation too?
If yes, is there anyway around it?

Thanks in advance.
Title: Re: UIScrollView
Post by: MartinG on July 01, 2014, 04:14:18 AM
Hi,

after updating to version 3.6.5 of NGUI I run into the problem, that the onDragFinished on UIScrollView isn´t fired anymore. I also tested with the latest version 3.6.6., it isn´t fired.

In my script I set

scrollView.onDragFinished = myFunction;

It worked with the older versions of NGUI (last version it worked was 3.5.3)

I also tried to set it that way:
      
scrollView.onDragFinished += myFunction;

Does not work.

In your UIScrollView the onDragFinished is fired only in the Press function, when it´s pressed is false.

In the LateUpdate function it´s never fired, because imMomentum.magnitude is always zero.

So, even if your onDragFinished is fired in scrollView "pressed == falser", my function does not fire anymore.

Did I some change or doing anything wrong? Or is this a bug in the new version?

Greetings,

Martin
Title: Re: UIScrollView
Post by: ArenMook on July 01, 2014, 05:14:52 AM
@MartinG: What are your settings on the scroll view? I just attached a simple test script to a default scroll view and it works as expected. Although the onFinished should not be getting called in Press(false) of a momentum-using scroll view -- that should get fixed.

@kennethljj: That limitation was on panels, and it's still the case. Panels should be scaled uniformly.
Title: Re: UIScrollView
Post by: MartinG on July 01, 2014, 07:57:27 AM
@ArenMook:

My ScrollView settings are:

Content Origin : TopLeft
Movement: Horizontal
DragEffect: Momentum
ScrollWheelFactor: 0.25
Momentum Amount: 35
Restrict Wihtin Panel: yes
Cancel Drag if fits: no
Smooth Drag Start: yes
iOS Drag Emulation: yes

I also tested with DragEffect: None and MomentumAndSpring

My function, which I set to

scrollView.onDragFinished = myFunction;

is not called. I tested the new onDragStarted with another function, and this worked.

My ScrollView settings are the same as with the version 3.5.3 of NGUI, there it worked. I will test it with another ScrollView, may be this will work ... or not.
Title: Re: UIScrollView
Post by: MartinG on July 01, 2014, 09:00:01 AM
@ArenMook:

Everything fine, I solved it.

I set the

scrollView.onDragFinished = myFunction

in the Awake() of my Behaviour. Now it´s in Start() and it works. (the setting of onDragStarted in Awake() still worked!)

I don´t know if something was changed in your UIScrollView, so that the onDragFinished may was "nulled" or "reseted" in it´s Start() Function. And may be it was just luck, that it worked within my Awake() Function in the past with NGUI 3.5.3 and older versions.

So, thanks for your help and keep up the good work! :)
Title: Re: UIScrollView
Post by: lazlo on July 04, 2014, 04:20:20 PM
Now that there isn't any UIDraggablePanel anymore, I'm can't find how to implement mouse wheel scroll. I have "Scroll Wheel Factor" to 1 but nothing happens. Are the steps outlined in some tutorial I missed?
Title: Re: UIScrollView
Post by: kitgui on July 05, 2014, 04:28:34 AM
Hey ArenMook, I've been working on a scrollview which dynamically adds elements to itself, with a Vertical Grid for repositioning newly instantiated elements.

I've noticed that when the Scroll Bar option Show Condition is set to OnlyIfNeeded or WhenDragging, the scrollview will start in odd positions sometimes (scrolled down from top by about 1 element's height), but if I set it to Always, that doesn't happen.

It's not a critical bug, I can live with Always, but I thought you should know.
Title: Re: UIScrollView
Post by: ArenMook on July 05, 2014, 11:07:52 PM
@kitgui: likely related to the order of events in your case. After instantiating objects you need to reposition the content, then reset the scroll view's position (and the scroll view's content bounds).

@lazlo: UIScrollView has a Scroll Wheel Factor and it will work assuming the Movement is set to Horizontal or Vertical. Note that you will still need UIDragScrollView in order for it to work or nothing will be receiving events.
Title: Re: UIScrollView
Post by: nookie on July 08, 2014, 10:14:49 AM
I had a very big problem with UIScrollView. I just can't understand how it works and why my code is not working. Simple scene:

UIScrollView, UIDragScrollView, UIGrid, UICenterOnChild
-Item (UICenterOnClick, UIDragScrollView)
-Item (UICenterOnClick, UIDragScrollView)
-Item (UICenterOnClick, UIDragScrollView)
...

Everything works fine, but I wanted to make first child to be on center when scene loads. I wrote the script:

  1. using UnityEngine;
  2.  
  3. public class CenterFirst : MonoBehaviour
  4. {
  5.     private void Update()
  6.     {
  7.         GetComponent<UICenterOnChild>().CenterOn(transform.GetChild(0));
  8.         enabled = false;
  9.     }
  10. }
  11.  

I attached this script to UIScrollView and run the scene. First element moved to the center of screen. Good! BUT when I click somewhere on scrollview it move all items to the left side of the screen! After this "jump" every next click works as expected: centers item on screen. If I run scene without CenterFirst script and click any item - everything works fine. So I think I did something wrong, but I can't understand what exactly. Where is my mistake?
Title: Re: UIScrollView
Post by: ArenMook on July 08, 2014, 01:31:22 PM
Wrong structure. Please follow the video more carefully next time, and use the right-click context menus. They wouldn't have allowed you to mess up your structure like that.

UIPanel, UIScrollView
- UIGrid, UICenterOnChild
-- Item (collider, UIDragScrollView)
-- Item (collider, UIDragScrollView)
-- Item (collider, UIDragScrollView)

Also make sure the scroll view has a proper Origin Point set.
Title: Re: UIScrollView
Post by: nookie on July 08, 2014, 01:47:04 PM
Quote
Wrong structure. Please follow the video more carefully next time, and use the right-click context menus. They wouldn't have allowed you to mess up your structure like that.
I changed structure like you said, but nothing changed - "jump" still in present.

UIPanel, UIScrollView
- UIGrid, UICenterOnChild, CenterFirst
-- Item (UICenterOnClick, UIDragScrollView, collider)
-- Item (UICenterOnClick, UIDragScrollView, collider)
-- Item (UICenterOnClick, UIDragScrollView, collider)

Quote
Also make sure the scroll view has a proper Origin Point set.
I don't understand what you mean.
Title: Re: UIScrollView
Post by: nookie on July 09, 2014, 01:28:41 AM
I still waiting for answer and support. Or this is bug?

P.S. One more problem: if I change the size of unity player window the "jump" is occur too. But this all happends only if ScrollView centers on the several first items and have a space on the left of them. Then if you click or change windows size it seems like reset position call. It more preferable for me if screen size changed - save focus on centered item. And, like I said above, first click should not call reset position. How to reach it?

P.S.2. I found source of bug - scroll bar. If I remove scroll bar everything (clicks, window resize) works without "jump". But what if I need scroll bar? What should I do?
Title: Re: UIScrollView
Post by: ArenMook on July 09, 2014, 02:40:41 PM
Content origin point -- it's set on the scroll view. Judging by you mentioning that resizing the unity player window causing the "jump", I'm going to guess that you have the scroll view anchored. Anchors are updated in the Update() function as well, same as your custom script. You can try modifying the script execution order in order to make your script execute after the Default Time so that its logic runs after the anchors have been updated.

You can force update scroll bars via UIScrollView's UpdateScrollbars() function. You can also reset the scroll bar's position after repositioning your items by simply updating the scroll bar's value.
Title: Re: UIScrollView
Post by: HeavensSword on July 22, 2014, 10:29:22 AM
Hello, I'm creating a type of chat log using a UITable full of UILabels and a UIScrollView.

In order to conserve memory I would like to only use a pool of 10 UILabels in an array (only 8 lines of text are visible anyways), but would like to scroll as if there were more (we're capping the max messages in the log to about 100).

So essentially I was wondering if there was a way for me to control the size of the scroll bar to fake there being more child UILabels than there actually are, giving the illusion that the user is scrolling through more than just 10.

Thanks in advance, and let me know if you need any clarification.
Title: Re: UIScrollView
Post by: ArenMook on July 22, 2014, 08:38:01 PM
The only way to do this would be to use the UIWrapContent script instead of a table. Just note that it positions things like a grid, without considering the widget's size like the table does.
Title: Re: UIScrollView
Post by: HeavensSword on July 23, 2014, 09:43:55 AM
Thanks ArenMook, i'll give it a try!
Title: Re: UIScrollView
Post by: jmansa on September 10, 2014, 02:23:09 PM
I was wandering if its possible to only render the items visible in the scrollview. Lets say I have a scrollview which fits about 8 items but my item list is on 50 items. Then I, as it is now, have to render all 50 and making the scrollview heavy!? Is there a function I am missing or is this not possible?

Hoping for help and thanks in advance :-)
Title: Re: UIScrollView
Post by: ArenMook on September 11, 2014, 01:49:20 AM
UIPanel has an option to cull the contents while dragging. Contents are culled automatically when not dragging the scroll view whether it's on or off. Objects that are culled don't get rendered.
Title: Re: UIScrollView
Post by: RDeluxe on September 24, 2014, 10:45:19 AM
Hi Aren,

I don't really get why my scrollview is not resetting its position when I'm dragging top. Here is a gif showing what happens :
(https://dl.dropboxusercontent.com/u/33151790/scroll.gif)

I don't really get why the scrollview is not repositionning its content correctly (at its top). Note that this happens only if there is not enough elements to vertically fill the scrollview.

Another problem that I face is that my grid elements go out of the UIPanel/UIScrollview :

Edit : This problem has been solved with a "Soft Clip" panel ... Sorry ;)

Here is my set up :

(http://i.imgur.com/Q63cexA.png)

"Restrict within panel" and "contraint within panel" are both checked.
Title: Re: UIScrollView
Post by: ArenMook on September 24, 2014, 02:48:55 PM
Scroll view won't reposition your content to the top if it fits. "Disable Drag if Fits" is one of the options on the scroll view. Otherwise you will be able to move the content around your scroll view freely.
Title: Re: UIScrollView
Post by: RDeluxe on September 24, 2014, 03:29:26 PM
Thanks. I'll use "disable if fits" for now, but I think that this kind of behavior can be quite nice (considering it's a basic one on iOS and Android, and well known to the users) :)
Title: Re: UIScrollView
Post by: kennethljj on September 26, 2014, 02:50:57 AM
Hi Aren,

Thanks for your clarification on my previous post regarding the limitations. I have another question regarding scroll view. Is it possible when the dragging ends, it will center to the nearest child object?

Eg. I have 2 instruction page and the user is to swipe left or right to view the pages. When the user swipe left it shld go to the next page and not stay in the middle of the 2 pages. I have a scroll bar that I have set the value to 2. It works perfectly when i use the scroll value but not in the case when the user drags the child object.

Hope you understand what I explained. Thanks in advance  :D

EDIT:

I have found the solution to this. :D
Decided to add the solution here for those who are looking for it as well. This is what my hierarchy looks like now:

UIScrollView
- UIGrid , UICenterOnChild
  ~ UIDragScrollView Objects
  ~ UIDragScrollView Objects

For more information, look at ngui scene example 7 :D
Title: Re: UIScrollView
Post by: jeldrez on October 06, 2014, 10:50:56 AM
How can I edit the Spring Panel strength in my UIScrollView?
I want it to spring but just a little.
Title: Re: UIScrollView
Post by: ArenMook on October 07, 2014, 10:51:34 AM
The obvious answer? SpringPanel.strength.

http://www.tasharen.com/ngui/docs/class_spring_panel.html#a95d8b533a8bd0e83703e18757df5bff0
Title: Re: UIScrollView
Post by: sx1n90 on October 17, 2014, 09:39:39 AM
How can i restrict overscroll amount when using MomentumAndSpring ???
Title: Re: UIScrollView
Post by: ArenMook on October 18, 2014, 09:06:45 AM
There is no such code in place.
Title: Re: UIScrollView
Post by: ababab5 on November 14, 2014, 01:50:07 PM
Hi,

I have an issue with the "touchable area" of my scroll view.

Please see this video of my issue :

https://www.dropbox.com/s/ro826crci029ic0/UIScrollView%20touch%20area%20issue.mp4?dl=0 (https://www.dropbox.com/s/ro826crci029ic0/UIScrollView%20touch%20area%20issue.mp4?dl=0)

How can I restrict the touch area to the UIPanel (all the size), and of course my widgets continue to go up if I swipe to the top , and go down if I swap to the bottom.


Thank you very much for your help.

Best regards,

AB
Title: Re: UIScrollView
Post by: ArenMook on November 15, 2014, 04:32:43 PM
Put it outside your scroll view. It shouldn't be a child of it.

Root
- Scroll View
-- Content 1
-- Content 2
-- Content 3
- UIWidget with UIDragPanel
Title: Re: UIScrollView
Post by: ababab5 on November 18, 2014, 06:20:35 AM
Hi,

thanks for your quick reply.

I tried and try again but it doesn't work : I can't drag anymore..

Do I miss something ?
Title: Re: UIScrollView
Post by: ArenMook on November 19, 2014, 04:15:14 PM
Did you reference the scroll view? It won't be able to find it on its own unless you reference it.
Title: Re: UIScrollView
Post by: ababab5 on November 19, 2014, 08:25:23 PM
Hi,

Thanks again for your reply.

What do you mean by "reference the scroll view" ?

Thanks
Title: Re: UIScrollView
Post by: ArenMook on November 20, 2014, 06:27:43 PM
The "Scroll View" field on the UIDragScrollView...
Title: Re: UIScrollView
Post by: ababab5 on November 25, 2014, 07:53:53 PM
Ok it takes time but it works. Thank you !
Title: Re: UIScrollView
Post by: Velvety on January 02, 2015, 11:00:46 PM
I've been searching the forums but haven't found a way to do this: I want to programmatically stop dragging a scrollview.  So far it seems like there is no easy way to do this. I may be able to "fake" ending a Press event or something, but I can't figure out how to reliably do that either.  Basically I want to be able to trigger the end of a press/drag on a scrollview so the user is forced to remove their finger and click/drag again if they want to start a new drag.  Is there a way to do this?  How might I cancel/end a drag that is in progress?  Thanks.
Title: Re: UIScrollView
Post by: ArenMook on January 04, 2015, 07:45:37 AM
UIScrollView.Press(false).
Title: Re: UIScrollView
Post by: jandrefcosta on January 08, 2015, 08:30:20 AM
Hello, I've some issues with the drag iOs style.
I want it works like native iOs scroll, with more movement than the regular configuration of the UIScrollView.
Let me explain. The movement of the drag elements is less soft, I need it more soft, more sliding, more duration when the finger release. Can I have that with the simple configurations on the panel, or I've edit the code behind the end movement ? The "Momentum and Spring" isn't enough end movement speed.

Thanks
Title: Re: UIScrollView
Post by: ArenMook on January 08, 2015, 09:12:17 AM
You will need to edit the code.
Title: Re: UIScrollView
Post by: alexh0101 on January 23, 2015, 04:11:05 PM
Hi,

How can I dynamically shift the scroll view to the n-th item of my grid?
I want the scrollview to show the n-th item when I press a button.

Can't find the property in question in UIScrollView's docs.

Thanks for your help
Title: Re: UIScrollView
Post by: ArenMook on January 23, 2015, 09:54:12 PM
Use SpringPanel.Begin. Check UICenterOnClick for an example.
Title: Re: UIScrollView
Post by: porchin on January 29, 2015, 01:14:13 AM
Hi Aren,

I'm a newbie for NGUI here. I tried to use a scroll view and found that there is an unexpected behavior similar to nerophon post here, has this issue been fixed? if not how can I fix it?

Quote
Hi,

We love the CenterOnChild behavior and are using it to tween our scrollView. Sadly, however, if a user taps / clicks during the tween, the tween is canceled (or overridden?) and the scrollView stops where it is. It does not even snap back to the nearest child.

How can we prevent this behavior? We want the scrollView to NOT stop tweening due to a user press, but a user swipe should still override it with a new tween in the new swipe direction.

Many thanks!

Nick

From my expectation
 - pressing should stop tweening
 - release should continue tweening
 - swipe should override the tween

Thanks in advance :)
Title: Re: UIScrollView
Post by: ArenMook on January 29, 2015, 01:27:04 PM
If this is what I'm thinking of, it was fixed a long time ago. What version of NGUI are you using?
Title: Re: UIScrollView
Post by: Plimsky on January 30, 2015, 04:01:17 AM
Hi,

I have a specific case with a scroll view.
I would like to be able to scroll with the scroll wheel vertically AND scroll with a scroll bar horizontally.
I tried with a Unrestricted movement but it doesn't work.

(http://uprapide.com/thumbs/invite/dev-leaderboard-gui-unity---3c---pc--mac---linux-standalone_1.png) (http://uprapide.com/919853-dev-leaderboard-gui-unity---3c---pc--mac---linux-standalone_1)

Any ideas ?
Thanks for the help ! :-)
Title: Re: UIScrollView
Post by: porchin on January 30, 2015, 09:44:46 AM
I'm using NGUI version 3.7.6p2 I think. It should be up-to-date enough, isn't it? Could you please check it again or do I set anything wrong?

(https://s3-ap-southeast-1.amazonaws.com/uploads-ap.hipchat.com/27628/457482/hYTFzCdNT9rWmBG/Screen%20Shot%202558-01-30%20at%209.41.51%20PM.png)
Title: Re: UIScrollView
Post by: ArenMook on January 30, 2015, 03:13:13 PM
@porchin: 376 is from November last year, so it's quite old now.

@Plimsky: You can set two scroll bars and Unrestricted movement no problem, but the scroll wheel will move both X and Y in this case. You would need to either modify the UIScrollView script to change this, or to set the Scroll Wheel Factor to 0 and write your own handler for the scrollwheel.
Title: Re: UIScrollView
Post by: porchin on February 02, 2015, 12:31:39 AM
Thanks! Aren. Got it :D

I'd like to ask more question, about UICenterChild's next page threshold. Can I do similar thing without using UIGrid?
I want my scroll view items to have gap between each others + have a threshold for scroll view to snap to the next item not to scroll to half way to make it snap to the next item.

Sorry for my bad English.
Title: Re: UIScrollView
Post by: ArenMook on February 02, 2015, 01:44:09 AM
I don't quite understand what you mean. The grid isn't necessary, it simply repositions the objects underneath it. You can remove it and position objects yourself if you prefer. To add padding to the scroll view, use invisible widgets to provide a larger covered area -- ALT+SHIFT+W.
Title: Re: UIScrollView
Post by: porchin on February 02, 2015, 04:25:22 AM
Normally UICenterOnChild will snap to the 2nd item if we scroll to more than half way between 2 items to get the 2nd item be "the nearest item" to snap right? I want to scroll only a bit, pass the threshold, to make scroll view snap to 2nd item like nextPageThreshold in UICenterOnChild does.
Title: Re: UIScrollView
Post by: dttngan91 on February 02, 2015, 05:44:48 AM
I have a issue deal with NGUI Scroll view performance in case of loading a list of nearly 500 items.
Currently, I loaded all items at the first time load game.Thus, I only enable the items which are viewed on camera space and disable the others. But when scrolling faster, it still jerky (not smooth) with really bad performance. Is there another ways to address this issue?


Title: Re: UIScrollView
Post by: ArenMook on February 03, 2015, 11:12:40 AM
You should let NGUI do the culling for you, not doing it yourself. UIPanel has an option "Cull". Also, 500 items is quite a lot. When scrolling, things come into view quite often, and you enabling/disabling things causes them to get added/removed from lists, causing the entire lists to be re-sorted. You may want to consider splitting up your content into different pages or categories.
Title: Re: UIScrollView
Post by: Xaren on February 10, 2015, 01:46:39 PM
Is there any way to find out if the Scrollview is at the bottom. Scrollbar value doesn't seem to be "1" after the user has moved it to the bottom.

(I want to detect that if the scrollbar is at the bottom, it should stay there when adding new object to it, but if it's not at the bottom, it should retain that position)

Thanks !
Title: Re: UIScrollView
Post by: ArenMook on February 11, 2015, 09:52:59 PM
Doesn't seem to be? It should be. Scroll bar's value ranges from 0 to 1 depending on the scrolled amount.
Title: Re: UIScrollView
Post by: Xaren on February 17, 2015, 09:51:16 AM
I was able to work with :

myScrollView.verticalScrollBar.value but even then, sometimes the value is 0.99XXXXX

(I was able to make it work, but it feel more like a patch than anything else)
Title: Re: UIScrollView
Post by: Finch on February 25, 2015, 10:22:17 AM
[solved]
I just solved this problem when i saw the same problem other person asked.
http://www.tasharen.com/forum/index.php?topic=4929.0

Original post
-----------------------------------------------------------------------------------------------------------------------------------
Sorry for my bad English.

I have an issue with UIScrollView.scrollView when scrollView value was changed.
Now, I have two different kinds of ScrollView, Horizontal scrollView for horizontal swipe, and vertical scrollView for vertical swipe.

Then I have a script called GestureSelection to change UIDragScrollView.ScrollView. But when scrollview value was changed,
the last scrollView jump to current touch point.

(http://i.imgur.com/Nz3MCX4.png?1)

(http://i.imgur.com/6KDeUdZ.png?1)


I hope you understand what i'm talking about. Sorry for my bad English again :'(.
Title: Re: UIScrollView
Post by: spbsmile on March 05, 2015, 10:10:04 AM
Hello !
 help, me)
 when i set UnityEngine.Time.timeScale = 0.0001;
 start delay from  UIScrollView.
how solved it ?
Title: Re: UIScrollView
Post by: ArenMook on March 05, 2015, 10:29:26 PM
Start delay of what?
Title: Re: UIScrollView
Post by: subliminalman on April 24, 2015, 06:47:02 PM
Is there a way to shift the upper bounds on a ScrollView to the center? I know there Center on child but I don't want it to "magnetize" to each button. I want the ScrollView to stop at the middle when it reaches it's first and last item instead of stopping at it's bounds.

[SOLVED]
I did this by unchecking Restrict Within Panel and doing my own clamp on the position and offset in an Update loop.
Title: Re: UIScrollView
Post by: Mourkain on February 09, 2016, 10:43:39 AM
I have two different ScrollViews. Both with 5 Items. One with Words and one with BackgroundImages for each word. When I center one of the Words, I call BackgroundImages.centerOn that Word.

This works good, when I go from word 2->3 or 3->4 or 3->5, but when I go from 4->1 it goes backwards, instead of forward, because I think centerOn takes the shortest way to the target.

Is there a way that it goes the same direction the WordScollView goes and not the shortest way or do I have to modify the UICenterOnChild for this?

Cheers,
Mourkain
Title: Re: UIScrollView
Post by: ArenMook on February 10, 2016, 05:55:02 PM
When you center on words you center on the background? I am not quite sure I understand you. If you are centering on something, I expect you to center on that, not on something else. I suggest having a look at the 14th example that comes with NGUI covering endless scroll views. The middle scroll view, one with the green cells, has centering on children, and it works as expected when you go from 9 to 1.
Title: Re: UIScrollView
Post by: chrisfirefox on February 12, 2016, 04:25:42 AM
Reset Position controls where the scroll view ends up when its position is reset programmatically. This value is relative to the width and height of the content. The starting value (0, 0) means top left corner. If you wanted a centered reset point, you would specify (0.5, 0.5).
A little request for updated documentation, as far as I understood the code, the "Reset Position" Values has been replaced with "Content Origin", but the documentation (first post of this topic) still states that it is there.
Title: Re: UIScrollView
Post by: ArenMook on February 12, 2016, 08:52:22 PM
Done, thanks.
Title: Re: UIScrollView
Post by: guoyuquan on April 26, 2016, 10:00:07 AM
Hi, I find that with the NGUI version 3.9.8, I cannot follow the tutorial video 4, in which the scroll view and add a sprite. I do all those that specified in the video, but I still cannot drag the sprite. What should I do.
Title: Re: UIScrollView
Post by: guoyuquan on April 26, 2016, 10:08:06 AM
got it. the reason is that the auto-adjust to match collider default set to disabled. And I didn't set the size of collider. sorry
Title: Re: UIScrollView
Post by: ivan_omni on October 05, 2016, 07:44:53 AM
I've made a build for android with the "Scroll View (Panel)" Example scene. In order to simulate a slow frame rate I've added:
  1. Application.targetFrameRate = 15;

In this scenario, the scroll view doesn't respond at all at fast drag gestures, remaining in the same position after the gesture. This only happens if the gesture is finished by stop pressing the screen (i.e., 1.-press 2.-drag 3.-stop pressing, all within 100~200ms).

This, as far as I understand, can potentially affect all games with frame rate problems.

Ideally, the scroll movement should be independent from frame-rate. Are there any plans to tackle this issue?

Thanks in advance!
Title: Re: UIScrollView
Post by: ArenMook on October 11, 2016, 10:57:39 AM
The movement is framerate-independent, but events are not. You may run into a situation where you press and release in the same frame, or press and release without an adequate amount of movement in between of the frames. Off the top of my head not much can be done about that.
Title: Re: UIScrollView
Post by: Dune on October 19, 2016, 02:03:43 PM
Following Tutorial 4...

Couldn't right-click on the camera or background to do the create. Had to use the top-bar NGUI menu.

Then I had a hard time getting the resize dots to appear, but now that I have them I cannot drag and resize the ScrollView as seen in the tutorial. The size only resizes by 2 pixels for a long drag. Then another 2, etc.

Just deleted the ScrollView and created another, and it's working fine. Thought I'd report the strange behavior.
Title: Re: UIScrollView
Post by: Dune on October 19, 2016, 02:15:19 PM
Can't right click on any NGUI object to get the context menu as you do in your videos. And left click to select is very difficult. I have to click dozens of times to get it. I usually revert to using the hierarchy to select.
Title: Re: UIScrollView
Post by: Dune on October 19, 2016, 03:22:12 PM
Struggling with the tutorial. So many things go wrong. Here's some screenshots when I add the Grid, put the sprites in it and then click Execute.

(http://i.imgur.com/1MbETvU.png)
(http://i.imgur.com/caTP21q.png)
(http://i.imgur.com/ycgzzZu.png)

Edit. Looking things over, the Grid has an XYZ scale of 205.5 and UI Root's XYZ scale of 0.004866, I'm sure that's messing with stuff. But I can't change the UI Root's scale to 1,1,1. They don't change from the 0.004866.
Title: Re: UIScrollView
Post by: ArenMook on October 19, 2016, 06:54:20 PM
Press "T". That activates rect transform, like Unity's UI. You have the move transform selected. The scale on your sprite is way off too... 0.004866? It should be (1, 1, 1). Check the scales of your objects.
Title: Re: UIScrollView
Post by: Dune on October 21, 2016, 12:20:34 AM
It turns out I needed to adjust the grid's cell sizes, and re-execute. But yeah, the scales are strange. I started over with a new project.

I've managed to follow most of tutorial 4. All except for being able to drag onto the single square, at the 12 minute mark on YouTube. See my comment there -

https://www.youtube.com/watch?annotation_id=annotation_4134838683&feature=iv&src_vid=jDxWG81sNPc&v=UK3aMHRfgcw
Title: Re: UIScrollView
Post by: ArenMook on October 24, 2016, 07:12:38 AM
Youtube is probably the worst place to ask questions. Stick to the support forum here, I actually read and reply here. :) Best to use http://www.tasharen.com/forum/index.php?board=1.0 though.
Title: Re: UIScrollView
Post by: BAIZOR on April 03, 2018, 12:34:58 PM
UIScrollView extention

I created extentions for UIScrollView, it helps getting vertical and horizontal scroll percent [0 - 1]
Check the ExtentionsUIScrollView.cs here - https://gist.github.com/IvanMurzak/2bad3244b5dd6dec266ceae0eb25d960

It works super easy. Just put the class in your unity project than you can write this anywere:

  1. UIScrollView scrollView;
  2.  
  3. float percentH = scrollView.PercentHorizontal();
  4. float percentV = scrollView.PercentVertical();
Title: Re: UIScrollView
Post by: ginxx009 on June 26, 2018, 10:32:00 PM
Hello guys I just wanted help for this. I created a 2 buttons (left and right) for scrolling to the next page. It's like a pagination thing .

Here's what I've got so far

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class NGUI_PageNavigation : MonoBehaviour {
  6.  
  7.     public GameObject sv;
  8.     public SpringPanel sp = null;
  9.     private const int xSpring = 1278;
  10.    
  11.  
  12.     // Use this for initialization
  13.     void Start()
  14.     {
  15.         sp = sv.GetComponent<SpringPanel>();
  16.         if (sp == null) sp = sv.AddComponent<SpringPanel>();
  17.        
  18.         sp.target.x = 0;
  19.         sp.target.y = 0;
  20.         sp.target.z = 0;
  21.     }
  22.  
  23.     public void LeftArrow()
  24.     {
  25.         if (sp.target.x >= 0)
  26.         {
  27.             sp.target = Vector3.zero;
  28.             sp.enabled = true;
  29.         }
  30.         else
  31.         {
  32.             sp.target = new Vector3(sp.target.x += xSpring, sp.target.y, sp.target.z);
  33.             sp.enabled = true;
  34.         }
  35.     }
  36.  
  37.     public void RightArrow()
  38.     {
  39.         sp.target = new Vector3(sp.target.x -= xSpring, sp.target.y, sp.target.z);
  40.         sp.enabled = true;
  41.     }
  42. }
  43.  
  44.  

What my problem is the VOID RIGHT ARROW

It exceeds even without object it still go endlessly. How can I stop that if the next page doesn't have an item it will springback to the last position.