Author Topic: UILabel Reposition problem  (Read 8720 times)

wongkh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
UILabel Reposition problem
« on: October 13, 2014, 09:49:06 PM »
Hi there, I have a problem for reposition few UILabels in Grid (Scroll View)..
I need it to go back top left when I come in this page again..
But somehow, there have a problem when my lines is more than certain numbers, It will not reposition...

This is my reposition code...Each time I click into it, it will reposition one time..
  1. if(!bIsReset)
  2.                         {
  3.                                 //temp = findchild(page010, "0_StreetView/003_Noticeboard_Details/Scroll View/Grid");
  4.                                 //temp.transform.localPosition = new Vector3(-280, 0, 0);
  5.                                 Noticeboard_Details_ScrollView.GetComponent<UIScrollView>().ResetPosition();
  6.                                 Noticeboard_Details_ScrollView.GetComponent<UIPanel>().Refresh();
  7.  
  8.                                 bIsReset = true;
  9.                         }

The problem I got is when the first time I press in it will look something like that, the position that I want should be on top left...


It will look perfect when I go in second time or have lesser lines..


Here is my gameObject..


When I test the longest lines, It will go like this, but if I go in second time, it will reposition to what I want...


Thanks for the help and sorry my bad English..
 :D :D

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Reposition problem
« Reply #1 on: October 14, 2014, 02:11:43 PM »
What version of NGUI, and are you actually ensuring that the widgets have been initialized before doing the panel reset? Because if you just enable or instantiate widgets, they won't be a part of the panel yet. That part is delayed until later. If you want to force the creation to happen right away, use NGUITools.ImmediatelyCreateDrawCalls.

wongkh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UILabel Reposition problem
« Reply #2 on: October 14, 2014, 10:02:20 PM »
I'm using Version 3.0.9 f2
Since this project have some time, so I afraid update to the latest version....
by the way, I'm enable (set to true) the parents(003_Noticeboard_Details) when I want this gameObject to be show on my screen..
Then I called the data from XML put it t UILabel... When this done, then only reposition the scroll view, grid, even UILabel...
So, when i don't need this gameObject, i just set it to false, to unable it...
The code I posted before is actually in update function, but it will only run once when it meet the condition....

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Reposition problem
« Reply #3 on: October 16, 2014, 05:47:38 AM »
Yeah unfortunately there isn't much I can do to help you with such an old version. It's about a year old now.

wongkh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UILabel Reposition problem
« Reply #4 on: October 16, 2014, 09:31:15 PM »
Oohhhh....
Then I have to upgrade to the latest one..
Yesterday I tried update to the latest version..
And I get this problem when I reposition it..


Even I use the NGUITools.ImmediatelyCreateDrawCalls, this problem still be there....
I'm not sure what happen about it...
Do you have any idea???

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Reposition problem
« Reply #5 on: October 17, 2014, 05:12:19 AM »
What code are you using to create the content there?

wongkh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UILabel Reposition problem
« Reply #6 on: October 17, 2014, 06:15:48 AM »
  1.                         item = (GameObject)Instantiate(Resources.Load(items_name));
  2.                                 item.transform.parent = Page003_Notification.transform;
  3.                                 item.transform.localScale = new Vector3(1,1,1);
  4.                                 item.name = "teacher_Overview_" + taskboard_Name(i);
  5.  

Position is added after created the contents
I tried to use AddChild, unfortunately I unable to work with it..
Not sure how to use AddChild in this case..
When I addChild, it only allow me Add gameObject Parents and bool undo (not sure what is this)...
Thanks for your help.....  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Reposition problem
« Reply #7 on: October 18, 2014, 08:26:59 AM »
item = NGUITools.AddChild(Page003_Notification.gameObject, Resources.Load(items_name));
item.name = "teacher_Overview_" + taskboard_Name(i);

wongkh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UILabel Reposition problem
« Reply #8 on: October 19, 2014, 11:12:37 PM »
I tried using AddChild and Latest version, but the problem still there..
It does not fixed the problem...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Reposition problem
« Reply #9 on: October 20, 2014, 11:22:50 PM »
What's the problem exactly? The content is not in the right place? What code are you using to reposition it? After all the items have been created, call Reposition() on the grid, then UIScrollView's ResetPosition() function. Although it's generally best to move the grid game object so that it's properly positioned to begin with. What I usually do is add a couple of items underneath the grid in edit time just so that I can see how it should all look like, then position the grid so that it's in the right place. I then delete the items under it, so that they get created at run-time. Since the grid was already positioned, I don't need to do anything else.

wongkh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UILabel Reposition problem
« Reply #10 on: October 21, 2014, 03:21:14 AM »
I think is the anchor problem...
I anchor it when I create the contents...
not worry much now..
I have fixed the problem by using other method to adjust the spacing between each cells...
Even the Label problem....
the reposition might delay, I just set a timer let it reposition every frame for 1 sec when I open it...
So, it will goes to the place I want....
Anyway, thanks for your reply..
:) (Y)