1. 程式人生 > >UGUI 學習筆記 9 Scrollbar 和ScrollView

UGUI 學習筆記 9 Scrollbar 和ScrollView

ScrollBar和ScrollView
1. ScrollBar屬性詳解

Interactable : Will this component accept input? 是否可用
Transition : Properties that determine the way the control responds visually to user actions. 狀態變化(詳解參考Button)
Navigation : Properties that determine the sequence of controls. 熱鍵關聯
Handle Rect : The graphic used for the sliding “handle” part of the control. 操作區域(滑塊 )
Direction : The direction in which the Scrollbar’s value will increase when the handle is dragged.The options are Left To Right,Right To Left,Bottom To Top and Top To Bottom. 方向
Left To Right 從左往右
Right To Left 從右往左
Bottom To Top 從下往上
Top To Bottom 從上往下
Value : Initial position value of the Scrollbar,in the range 0.0 to 1.0. 滑動條的值
Size : Fractional size of the handle within the Scrollbar,in the range 0.0 to 1.0. 滑塊的尺寸
Number Of steps : The number of distinct scroll positions. 分節數量
On Value Changed : A UnityEvent that is invoked when the current value of the Scrollbar changes. The event can send the value as a float type dynamic argument. 事件

2. ScrollView 中的 Scroll Rect屬性詳解

Content : This is a reference to the Rect Transform of the UI element to be scrolled,for example a large image. 內容顯示區
Horizontal : Enables horizontal scrolling 水平滑動
Vertical : Enables vertical scrolling 垂直滑動
Movement Type : Unrestricted,Elastic or Clamped.Use Elastic or Clamped to force the content to remain within the bounds of the Scroll Rect. Elastic mode bounces the content when it reaches the edge of the Scroll Rect. 移動型別
Elastic : 回彈模式 (移動到底後回回彈)
Clampes : 夾子模式(移動到底不會回彈)
Elasticity : This is the amount of bounce used in the elasticity mode. 回彈模式的,回彈量。
Inertia When Inertia is set the content will continue to move when the pointer is released after a drag. When Inertia is not set the content will only move when dragged. 慣性
Deceleration : Rate When Inertia is set the deceleration rate determines how quicky the contents stop moveing.A rate of 0 will stop the movement immediately. A value of means the movement will never slow down. 減速率
0 立刻停止。
1永不停止。
Viewport : Reference to the viewport Rect Transform that is the parent of the content Rect Transform. 內容顯示區域
Horizontal Scrollbar : Optional reference to a horizontal scrollbar element. 水平滾動條
Visiblity : Whether the scrollbar should automatically be hidden when it isn’t needed,and optionally expand the viewport as well. 是否可見
Permanent 一直可見
Auto Hide 自動隱藏
Auto Hide And Expand Viewport 自動隱藏和擴充套件滾動條。

Spacing : The space between the scrollbar and the viewport. 滾動條和內容顯示區域的距離
Vertical Scrollbar : Optional reference to a vertical scrollbar element. 垂直滾動條
On Value Changed : A UnityEvent that is invoked when the scroll position of the Scroll Rect changes. The event can send the current scroll position as a Vector2 type dynamic argument. 事件

3. ScrollView 中的 Mask屬性詳解

Show Graphic : Should the graphic of the masking(parent) object be drawn with alpha over the child object? 顯示圖片。
4. ScrollBar使用詳解
新增Scrollbar GameObject或者在GameObject 中新增Scrollbar指令碼。如果想要限制滑塊的滑動次數。將Number Of Steps設定成想要的值。例如設定成3,滑塊只能拖動3次。設定成0和1 都是沒有效果,設定成2,則一下到底,或者一下到頂。
設定如圖
這裡寫圖片描述
如果要用滑鼠滾輪控制滑塊,則需要在Scrollbar中繫結如下程式碼。
這裡寫圖片描述
例子:超長圖片的顯示
設定好Scrollbar,新增顯示區視窗,在顯示區視窗新增Scroll Rect指令碼和Mask指令碼
這裡寫圖片描述
image新增圖片,scrollrect繫結content,繫結scrollbar
這裡寫圖片描述
設定width,height,最終效果如下圖
這裡寫圖片描述

例子:多個控制元件的顯示
設定好Scrollbar,新增顯示區視窗,在顯示區視窗新增Scroll Rect指令碼和Mask指令碼
scrollrect繫結content,繫結scrollbar
這裡寫圖片描述

這裡寫圖片描述

content 顯示區物件添加布局指令碼,這裡用的是Grid Layout Group
設定好Padding ,內邊距,Cell Size ,子控制元件的大小,Spacing,外邊距。
解釋下Grid Layout Group

Padding : The padding inside the edges of the layout group. 內邊距
Cell Size : The size to use for eache layout element in he group. 子控制元件的大小
Spacing : The spacing between the layout elements. 外邊距
Start Corner : The corner where the first element is located. 開始位置
Upper Left 左上
Upper Right 右上
Lower Left 左下
Lower Right 右下
Start Axis : Which primary axis to place elements along.Horizontal will fill an entire row before a new row is started. Vertical will fill an entire column before a new column is started. 排列方向
Horizontal 水平
Vertical 垂直
Child Alignment : The alignment to use for the layout elements if they don’t fill out all the available space. 子控制元件對齊方式
Upper Left 左上
Upper Center 中上
Upper Right 右上
Middle Left 左中
Middle Center 正中
Middle Right 右中
Lower Left 左下
Lower Center 中下
Lower Right 右下
Constraint : Constraint the grid to a fixed number of rows or columns to aid the auto layout system. 約束條件
Flexible 自動
Fixed Column Count 固定列數
Fixed Row Count 固定行數

在顯示區物件下,新增多個image.
這裡寫圖片描述
效果如下圖
5. ScrollView的使用詳解
這裡寫圖片描述
ScollView 控制元件下右三個組成部分,Viewport 檢視,Scrollbar Horizontal ,水平滾動條, Scrollbar Vertical ,垂直滾動條。也就是說製作ScrollView要有1 滑動條,2檢視,指令碼1.scroll Rect ,2 mask,3 Grid Layout Group,4 Scrollbar 。有了這些就可以製作想要的ScrollView。這些指令碼的設定參考上一步。
例子:遊戲裡玩家排行彈窗
首先設定ScrollView
想的是手機端,所以去掉了滑動條。玩家數量是動態變化的,content的大小也該跟這變化,所以添加了Content Size Fillter指令碼,實現Content 大小的動態變化,解釋下 Content Size Fitter。

Horizontal Fit : How the width is controlled. 寬度適配
Vertical Fit : How the Height is controlled. 高度適配
None/Unconstrained : Do not drive the width/height based on the minimum width/height of the layout element. 不調整
Minimum/Min Size : Drive the width/height based on the minimum width/height of the layout element. 根據子控制元件中最小的寬或 高度,子控制元件數量 調整顯示區大小。
Preferred/Preferred : Size Drive the width/height based on the preferred width/height of the layout element. 根據Grid Layout Group 中Cell Size 和 Spacing的值,子控制元件的數量, 調整顯示區的大小。
Content Size Fitter 設定如下
這裡寫圖片描述
調整Mask大小
這裡寫圖片描述
其次自定義item
這裡寫圖片描述

這裡寫圖片描述

這裡說下UGUI 的層級問題,NGUI 中層級是由 Panel 和控制元件中的 depth來控制,而 UGUI中石油Canvas和GameObject渲染的先後順序。
Canvas 是同一個渲染模式下,由sort order的值決定的。
這裡寫圖片描述
其他子控制元件,直觀的來看就是場景中Game Object的排列順序,越往後越靠上如圖所示
這裡寫圖片描述
然後設定背景,調整canvas層級
這裡寫圖片描述
最後新增程式碼,動態新增item
彈出主體程式碼如下
這裡寫圖片描述
Item程式碼如下
這裡寫圖片描述
在彈窗主體中繫結 content 的transform,和item預製體
這裡寫圖片描述
最終效果如下圖
這裡寫圖片描述

相關推薦

UGUI 學習筆記 9 Scrollbar ScrollView

ScrollBar和ScrollView 1. ScrollBar屬性詳解 Interactable : Will this component accept input? 是否可用 Transition : Properties that

資料結構學習筆記9--棧佇列的順序儲存結構

棧和佇列的相同點和不同點: 相同點:棧和佇列是兩種重要的資料結構,也是兩種特殊的線性表結構。從資料的邏輯角度看,棧和佇列是線性表;從操作的角度來看,棧和佇列的基本操作是線性表基本操作的子集,是操作受限

Android學習筆記9-呼叫攝像頭相簿

呼叫攝像頭和手機的相簿 呼叫手機的攝像頭和相機拍照的功能,在許多app中都非常常見,當我們用qq,微信,微博等app給別人分享圖片時都會用到這個功能。 1,呼叫攝像頭拍照 activity_main.xml佈局程式碼 <?xml version="1.0" enc

PyTorch學習筆記(9)——nn.Conv2d其中的padding策略

一. Caffe、Tensorflow的padding策略 在之前的轉載過的一篇文章——《tensorflow ckpt檔案轉caffemodel時遇到的坑》提到過,caffe的padding方式和tensorflow的padding方式有很大的區別,輸出無法

ES6學習筆記9 Symbol、SetMap

SymbolES6引入一種新的資料型別Symbol,表示獨一無二的值。Symbol值通過Symol函式生成,可傳入一個字串引數,表示對Symbol例項的描述(即使兩個Symbol描述相同,值也不同),用於區分不同的Symbol值。let s1 = Symbol('foo');

Android學習筆記(9):使用XML檔案Java程式碼控制UI介面

Android推薦使用XML檔案設定UI介面,然後用Java程式碼控制邏輯部分,這體現了MVC思想。 MVC全名是Model View Controller,是模型(model)-檢視(view)-控制器(controller)的縮寫,一種軟體設計典範,用一種業務邏輯、資

js-ES6學習筆記-Set結構Map結構

基本類 實例 記錄 lba post 而且 同名 方法 zha http://www.cnblogs.com/lonhon/ 1、ES6 提供了新的數據結構 Set。它類似於數組,但是成員的值都是唯一的,沒有重復的值。 Set 本身是一個構造函數,用來生成 Set 數

【JAVAWEB學習筆記】23_Listener郵箱服務器

添加 .get 接收 監聽 lin 感知 一個 rate 包括 監聽器Listener 學習目標 案例-使用監聽器完成定時生日祝福 一、監聽器Listener javaEE包括13門規範 在課程中主要學習 servlet技術 和 jsp技術 其中

Android:日常學習筆記(9)———探究廣播機制

ora rri enabled cas 管理 encoding protect 其他 acc Android:日常學習筆記(9)———探究廣播機制 引入廣播機制 Andorid廣播機制   廣播是任何應用均可接收的消息。系統將針對系統事件(例如:系統啟動或設備開始充電時)傳

ThinkPHP5學習筆記(6)請求響應

thinkphp在線視頻課程:http://www.kancloud.cn/tpshop/thinkphp5/220692Request請求對象和Response響應對象$_GET、$_POST、$_REQUEST、$_COOKIE調用請求對象$request=Request::instance()$this

sqlite學習筆記9:C語言中使用sqlite之插入數據

name article void num mes cut cpp content int 前面創建了一張表,如今給他插入一些數據。插入數據跟創建表差點兒相同,不過SQL語言不一樣而已,完整代碼例如以下: #include <stdio.h> #inclu

NLTK學習筆記(五):分類標註詞匯

推廣 默認 註意 max() 上下 efault val 存儲 n-n [TOC] 詞性標註器 之後的很多工作都需要標註完的詞匯。nltk自帶英文標註器pos_tag import nltk text = nltk.word_tokenize("And now for

機器學習筆記 1 LMS梯度下降(批梯度下降) 20170617

temp eas 理解 import 樣本 alt mes show 超過 # 概念 LMS(least mean square):(最小均方法)通過最小化均方誤差來求最佳參數的方法。 GD(gradient descent) : (梯度下降法)一種參數更新法則。可以作為L

python學習筆記9:正則表達式

使用 引入 常用 常用的正則表達式 需要 style pan 表達式 span 一、簡介   正則表達式就是用來查找字符串的;用來匹配一些比較復雜的字符串。   使用正確表達式需要引入re模塊 (regular定期的有規律的)    二、匹配字符串的方法

Java學習筆記-12.傳遞返回對象

使用方法 自己 ots 返回 stringer integer print util solid 1.Clone()方法產生一個object,使用方法後必須產生的object賦值。 Vector v2 = (Vector)v.clone(); 2.Clone()方法在ob

Java學習筆記—抽象類接口

compute nal java語言 通過 多個 靜態代碼塊 容易 如果 span 1.抽象類 在Java語言中使用abstrac關鍵字來定義抽象類和抽象方法,抽象方法沒有定義,方法名後面直接跟一個分號,而不是花括號。 public abstract class Empl

python學習筆記9:面向對象編程,類

數據 相同屬性 技術 -o 必須 是把 oop ack 繼承 一、面向對象編程   面向對象--Object Oriented Programming,簡稱oop,是一種程序設計思想。   還有另一種程序設計思想——面向過程編程。面向過程的思想是把一個項目、一件事情按照一定

Android 學習筆記--9妹圖片+代碼混淆+打包

文件名 打包 andro span apk 使用 背景透明 學習筆記 tro 一、Android Studio 創建.9文件 註:找一張背景透明的png圖片,將文件名改成 " xxxx.9.png " 然後放到drawable文件中,雙擊 註:有一種

java學習筆記--類ArrayListLinkedList的實現

java 集合 list 在集合Collection下的List中有兩個實現使用的很頻繁,一個是ArrayList,另一個是LinkedList,在學習中肯定都會有這樣的疑問:什麽時候適合使用ArrayList,什麽時候用LinkedList?這時,我們就需要了解ArrayList和Lin

iOS學習筆記37-時間日期計算

htm chinese 區域 nsis ios geo 代號 keyword 轉換 一、時間和日期計算 我們在應用開發中,時常須要和時間打交道,比方獲取當前時間,獲取兩個時間點相隔的時間等等,在iOS開發中與時間相關的類有例如以下幾個: 1. NSD