0

I have a single image that is displayed inside a scrollRect.. pivot is centered and the user is able to scale the image up and down using a slider.. then he/she is able to scroll drag the image around (with the scrollRect functionality) like for example a page in a book-app.. but when the user scales the image up and drags it around and then scales it back down again, the page shrinks at its own pivot point and sometimes gaps are visible on the sides depending on where the user has dragged the image.. When you start to drag the image again it snaps to the correct location but it doesn't look very polished when you force a user to "nudge" something before it snaps into place..

does anybody know of a way to invoke the "nudge" after scaling? Or force the ScrollRect to calculate the position of the image after scaling? I tried using math and pivot points but since the position alters with both scaling and dragging I can't hardcode a value to change pivot points (like f.e. if x < -50 and y < -50 then the pivot point should be top right) ..

The simplest solution would be to invoke that little nudge the user has to do now but I don't know how I have to go about doing it (just changing the transform.positon.x in code doesn't work, the scrollRect needs to update its content) or maybe I could reset the position of the anchor so it stays at the center of the parent..

I tried to clarify with some images: https://ibb.co/f7Oxk6

  • Did you try [Rebuild?](https://docs.unity3d.com/ScriptReference/UI.ScrollRect.Rebuild.html) – obywan Nov 24 '17 at 14:00
  • Sorry no I did not.. I tinkered with the code a while with your suggestion but couldn't get the rebuild function to work (properly).. I added ".Rebuild(CanvasUpdate.Layout); in the method that handles the scaling" to both the Image and the ScrollRect it's on but it doesn't seem to do anything.. – dieterweireldt Nov 24 '17 at 16:31
  • I just thought of something, if I set the pivot point of the Image to the center of it's parent object (the ScrollRect) wouldn't that eliminate the gaps? However I can't seem to figure out how to set the pivot to a particular x,y coordinate.. it just wants to use a float between 1 and 0 (top, bottom and everything in between) – dieterweireldt Nov 25 '17 at 12:42
  • So, wouldn't 0.5 and 0.5 mean center? – obywan Nov 25 '17 at 16:04
  • of the image, yes but it needs to be the center of the container object but for some reason it doesn't want to take those coordinates.. – dieterweireldt Nov 26 '17 at 17:06

0 Answers0