1.所有的图片宽度要相同(最好)
2.锚点设置
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ScrollImageScale : MonoBehaviour { public Image image; public GameObject content; private float startX; private void Start() { startX = image.transform.localPosition.x; print(startX); } private void OnEnable() { Invoke("InvokeFun", 0.01f); } void InvokeFun() { image.SetNativeSize(); content.transform.localPosition = new Vector3(0, 0, 0); float imageHight = image.GetComponent<RectTransform>().sizeDelta.y; image.transform.localPosition = new Vector3(startX, -imageHight/2-5, 0); RectTransform rectFransF = content.transform.GetComponent<RectTransform>(); rectFransF.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (imageHight+10f)); } }
标签:startX,image,transform,Unity,using,Scroll,View From: https://www.cnblogs.com/zqiang0803/p/18335988