Scroll View 组件使用基础

来源:互联网 发布:软件测试的生命周期 编辑:程序博客网 时间:2024/06/09 17:18

Scroll View 在unity当中非常的实用,也很容易使用。

Scroll View面板


属性 意义 Content 可以被拖拽的容器。 Horizontal 是否可以水平拖拽 Vertical 是否可以竖直拖拽 MovementType 移动类型 Inertia 是否启用运动惯性 DecelerationDRate 运动减速的速度。 Scroll Sensitivity 滚动的敏感度 Viewport 引用作为RectTransform的父内容的视口RectTransform。 Horizontal Scrollbar 可选的Scrollbar对象,链接到ScrollRect的水平滚动。 Vertical Scrollbar 可选的Scrollbar对象,链接到ScrollRect的竖直滚动。 Visibility 可见性模式。 Spacing 滚动条和viewport之间的空间
MovementType type Unrestricted 可以无限制拖动 Elastic 允许内容暂时移动超过容器,但是弹性地拉回,Elasticity-弹性值 Elastic 内容无法移动超出其容器
Visibility type Permanent 总是显示拖动条 AutoHide 在此轴上不需要滚动时自动隐藏滚动条。 viewport rect不会被更改。 AutoHideAndExpandViewport 在此轴上不需要滚动时自动隐藏滚动条,并相应地展开viewport rect。

在Scroll View中添加Grid Layout

这里写图片描述

grid中如果存在需要点击的组件,则需要挂载上Button类,然后使用如下方法, 就可以在保证拖拽的情况下可以进行点击操作

    void Start()    {        //如此挂载,主要是为了解决scrollview和button的互动冲突        _button = GetComponent<Button>();        _button.onClick.AddListener(delegate() {            //执行方法        });    }    void OnDestroy()    {        if (_button != null)            _button.onClick.RemoveAllListeners();    }
原创粉丝点击