Scroll View
组成
Scroll Rect组件
Content:可以滚动的内容,该对象必须是带有Scroll Rect的子控件
Horizontal:数据是否可以水平拖动
Vertical:数据是否可以垂直拖动
Movement Type:内容超出容器时的行为
- Unrestricted:无限制。不受限制的运动。 内容可以永远移动。
- Elastic:弹性运动。 允许内容暂时移出容器,但弹性拉回。
- Elasticity:弹性
- Clamped:内容无法移动到其容器之外。
Inertia:是否启用运动惯性
- Deceleration Rate:当Inertia勾选时有效,减速率,运动减慢的速度
Scroll Sensitivity:滚动灵敏度
Viewport:视口,即是内容的容器
Horizontal Scrollbar:水平滚动条
- Visibility:
- Permanent:始终显示滚动条
- AutoHide:自动隐藏
- AutoHideAndExpandViewport:
Spacing:间距
Vertical Scrollbar:垂直滚动条
- Visibility:(同上)
事件绑定
ScrollRect scrollRect = GameObject.Find("Scroll View").GetComponent<ScrollRect>();
scrollRect.onValueChanged.AddListener((vector2) =>
{
print(scrollRect.name + "的水平滚动条的进度:" + vector2.x + ",垂直滚动条的进度:" + vector2.y);
});
拖动拖动垂直滚动条时
Mask组件
Viewport上的一个组件,当内容超出Viewport时,内容自动隐藏
Show Mask Graphic:显示与Mask渲染区域关联的图形。
在Viewport下的Content中添加Text组件,添加文本进行测试
有无Mask组件的区别