Author Topic: UIScrollView  (Read 203316 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #30 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.
« Last Edit: March 07, 2014, 10:58:31 AM by ArenMook »

nzen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: UIScrollView
« Reply #31 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() 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.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIScrollView
« Reply #32 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #33 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.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIScrollView
« Reply #34 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.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #35 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;

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIScrollView
« Reply #36 on: March 13, 2014, 02:38:59 AM »
Thanks for that ArenMook, I've adapted that to work fine.

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #37 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #38 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?

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #39 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.
« Last Edit: March 20, 2014, 06:58:25 PM by AbsurdInteractive »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #40 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.

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #41 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.

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #42 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView
« Reply #43 on: March 22, 2014, 09:21:10 PM »
UICenterOnChild hasn't changed recently. UIGrid has a Pivot point in 3.5.5.

AbsurdInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIScrollView
« Reply #44 on: March 23, 2014, 02:22:32 PM »
It looks like 3.5.5's Grid Pivot Point option fixed everything. :) Thanks.