using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScrollViewTool : MonoBehaviour
{
void Awake()
{
ScrollRect scrollRect = GetComponent<ScrollRect>();
float height = GetComponent<RectTransform>().sizeDelta.y;
float scrollViewHeight = height <= 0 ? Screen.height / (Screen.width / 720f) + height : height; // 计算ScrollView高度 height<0则UI布局是拉伸布局 720是设置的以屏幕适配宽度(以宽为基准)
if (scrollViewHeight < scrollRect.content.rect.height)
{
scrollRect.vertical = true; // 修改ScrollView的拖拽为可拖拽
}
else
{
scrollRect.vertical = false; // 修改ScrollView的拖拽为不可拖拽
}
}
}
针对Unity ScrollView Elastic模式 Content自动修改是否可拖拽
最新推荐文章于 2023-10-14 08:19:46 发布