Author Topic: ui texture resize on device orientation change problem  (Read 14662 times)

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 31
    • View Profile
ui texture resize on device orientation change problem
« on: August 10, 2016, 06:48:17 PM »
hello everyone!
i'm trying to create an image gallery with NGUI for my app in ios/android, but i have a huge problem:
i am using a grid filled with uitexture with fixed aspect flag set, in this way my images keep their ratio in fullscreen.
the problem is when i rotate my device in widescreen, the image result small in the center of the screen, there is a way to update my uitexture for fill the screen when i rotate my device?
sorry for my english, please any help is appreciated : )
thank you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ui texture resize on device orientation change problem
« Reply #1 on: August 13, 2016, 03:45:21 PM »
Fixed aspect simply forces the width or height on the opposite's value. I'm going to guess that you have your sprite's with or height anchored to the screen, so when the screen rotates and its width/height changes, so do your sprites.

Simple solution: either don't anchor to the screen, or don't use fixed aspect ratio. If you are simply trying to keep the image's dimensions, don't re-adjust them in the first place. Also, assuming you are the one that sets the textures in the first place, you can also adjust the dimensions right then and there as you need them to be.

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: ui texture resize on device orientation change problem
« Reply #2 on: August 13, 2016, 04:32:51 PM »
first of all thanks for your reply as always!
sorry i don't understand your solution i'm so noob : )
i have an uitexture prefab, his dimensions is equal to screen dimension, no anchors.
when i have to instantiate it i put a texture on it picked from android/ios gallery, if i don't set "fixed aspect" the texture fill all the screen, if i set "fixed aspect" on the prefab my texture ratio is correct, but when i rotate the device  i need to update uitexture h/w for wide, i attach to this post an example image, maybe you understood that right and i don't understand your solution, in that case please try to explane that again to me : (
thanks!

EDIT: the second images is different my bad XD but they have the same ratio so i suppose is clear enough : )

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ui texture resize on device orientation change problem
« Reply #3 on: August 17, 2016, 07:02:29 AM »
Select your UIRoot. Change its scaling style to Constrained. Set its content width and height to the same value, matching the height of your screen. For example 1080. Check both "Fit" checkboxes next to width and height.

Now get rid of the aspect ratio setting on your image. It's not needed.