Author Topic: Vertically scrolling UIScrollView not starting in the correct position  (Read 16760 times)

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
So I think I have everything set up properly with my scroll view.

However, my scroll view content is never exactly in the correct spot upon launching the game. I think this may be due to the fact that the size of the scroll view changes depending on the resolution of the screen.

I can fix the issue by running "Reset Clipping Position" on the "UIScrollView" script via the inspector, right after starting the game. I tried adding ResetPosition() to the Start() method, but for some reason this does not fix the issue.

Am I missing something?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
In which Start()? Did you set your scroll view's origin point? UIScrollView's ResetPosition() function is what gets called when you right-click it and choose Execute in the inspector. If you are trying to do it in your script's Start() function you will want to make sure that it executes after the scroll view.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
As a temporary experiment, I added it to the start() method of the UIScrollView script. However, I noticed that the signature is "protected virtual void Start ()"  rather than "void Start ()". Could that have something to do with my idea not working?

The origin points all seem to be good. I think if they were wrong, it wouldn't be fixed by running ResetPosition after the game had started. On the contrary, running ResetPosition after the GUI is done loading (applying OnEnable anchors/etc) puts the ScrollView content *exactly* where it should be.

Just some additional data btw:

UIScrollView
Content Origin: Top
Movement Vertical
Drag Effect: MomentumAndSpring
RestrictWithinPanel: true
ScrollBars: none

UIGrid
Arrangement: Horizontal
Sorting: Vertical
Pivot: Top
MaxPerLine: 1

And each element in the grid is anchored to its top-center.

Regarding the attachment: This is how it should look, and how it does look after running ResetPosition. Otherwise, it's usually about 50-100 pixels offset from where it should be.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Well, as I mentioned above, "If you are trying to do it in your script's Start() function you will want to make sure that it executes after the scroll view." -- so your "contrary" statement is actually what I suggested.

In regards to your pic... there is a gap between the content's top and the scroll view's top, and if the scroll view's content is top-left based, then running Execute/ResetPosition() will move the content up.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
I dont think there's any problem with the gap that you see. When moving the panel around with the mouse that's the same spot that it "springs" back to. I am using a "fade" effect though so I'm glad that it works that way. No complaints.

As for the suggestion, I'd like to change the UIScrollView script and not my own, so that I do not need a "fixer" script for every scroll view I have. It definitely seems like something that UIScrollView should be responsible for anyway.

Also, there's actually a second "bad offset" issue going on that might/might not be related. I am quite sure that this is either an NGUI bug or an NGUI "gotchya" that I'm not aware of. I've included a screenshot of it in this reply. The area that I tinted blue is a UIWidget, and the area tinted purple contains UILabels.

As a bit of background, the text only falls out of alignment when doing a position tween on the top-level parent of the whole "window". As you can see, some text is scooted too far to the left and clearly falls outside of its own bounding box which should never happen. Its completely random in which labels get effected, and if you scroll the content off-screen it will sometimes correct itself.
« Last Edit: June 04, 2014, 08:51:47 PM by Wisteso »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Indeed the text should never go outside the bounds. I can only think of this happening due to something in the UI hierarchy leading up to the label having a scale of zero. If that's not it and you find a way to reproduce it consistently, I'd love to know how.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Aren, since it's been a while, so I just wanted to let you know that I plan to give you the files needed to reproduce this. It's just a bit tricky to strip our project down to the UI only.

I'm letting you know ahead of time so you don't have to waste any effort trying to recreate the symptoms.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #7 on: August 11, 2014, 12:28:07 PM »
ArenMook:

Have you been able to check out the reproduction case I sent? This is definitely a pretty significant problem for us, without a known workaround. I can help via Skype/GoogleHangout/etc if you need.

Thank you

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #8 on: August 12, 2014, 04:00:21 AM »
Where did you send it? I don't have any outstanding projects to look at right now.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #9 on: August 12, 2014, 02:54:19 PM »
I originally sent it using the forum PM system, but considering my "sent" items are now empty, it seems the forum might have eaten it somehow.

I just sent another message using the "contact me" feature at http://www.tasharen.com/?page_id=104 - I would post the link here but since it contains our company's int. prop., I cant post it publicly.

I can create a 3-minute video (mp4) demonstration of how to reproduce the issues if my text explanation is lacking.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #10 on: August 13, 2014, 07:39:11 AM »
Yup, I got it this time, thanks.

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #11 on: August 13, 2014, 08:56:50 AM »
does the problem go away if you add scrollbars to the scrollview?

I posted on another thread something very similar and adding scrollbars (although not desired) did set the contents to the correct position.
« Last Edit: August 13, 2014, 11:22:31 AM by beermoney »

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #12 on: August 14, 2014, 04:18:59 AM »
Beermoney, I tried adding scrollbars. It didn't solve the issue, but thanks for the idea.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Re: Vertically scrolling UIScrollView not starting in the correct position
« Reply #13 on: August 30, 2014, 11:15:54 PM »
I think this issue may be solved in 3.7.1. I just upgraded to the version today (from 3.5.8) and haven't seen the issue occur yet. I'll post again if the issue reoccurs with 3.7.1.