php年月日滚动选择,Unity3d—做一个年月日选择器(Scroll Rect拖动效果优化)— 无限滚动 + 锁定元素...

[导读]最近.....废话不多说上效果图用的是UGUI我先说思路通过判断元素的位置信息来改变Hierarchy的顺序 实现无限滚动改变位置的同时也要不断的调整Content的位置防止乱跳元素锁定就是直接锁死的元素的移动范围 当只有拖动大于一定程度时

最近.....

废话不多说上效果图

1176379-20170612223836821-839466076.gif

用的是UGUI

我先说思路

通过判断元素的位置信息来改变Hierarchy的顺序 实现无限滚动

改变位置的同时也要不断的调整Content的位置防止乱跳

元素锁定就是直接锁死的元素的移动范围 当只有拖动大于一定程度时才会发生改变

1176379-20170612224250431-1825163802.gif

然后是面板设置

整体结构是这样子的

1176379-20170612224915368-256964478.png

需要注意的是Content需要的两个组件

1176379-20170612225117900-683708447.png

Content的爸爸只需要一个脚本

1176379-20170612225208196-1658570451.png

大小改变曲线(大致就行)

1176379-20170612225301306-1867155414.png

颜色渐变曲线

1176379-20170612225313071-1706028318.png

最后是脚本using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.EventSystems;

using UnityEngine.UI;

public class DateControl : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {

public enum ItemType { _year, _month, _day }

public ItemType _itemtype;

RectTransform conentRect;

RectTransform targetRec;

Vector3 oldDragPos;

Vector3 newDragPos;

public AnimationCurve curve_scale;//改变大小曲线

public AnimationCurve curve_color;//渐变效果曲线

List textList = new List();

Button testBtn;

float

itemHeight,             //子项item的高

contentParentHeight,    //Content爸爸的高

itemNum,                //子项数量

itemHeight_min,         //子项最小发生改变位置

itemHeight_max,         //子项最大发生改变位置

conentLimit,            //Conent纠正位置

conentSpacing;          //子项间隔大小

float deltaX, deltaY;

[HideInInspector]

public static int _year, _month, _day;

[HideInInspector]

int dateItemNum;

Color itemColor_hig = new Color32(255, 255, 255, 255);

void Awake() {

conentRect = transform.FindChild("Content").GetComponent();

targetRec = transform.parent.FindChild("HighlightTarget").GetComponent();

}

void OnEnable() {

ItemList();

}

void Start() {

switch (_itemtype) {

case ItemType._year: InstantiateData(15, 2017); break;

case ItemType._month: InstantiateData(12, 12); break;

case ItemType._day: InstantiateData(31, 31); break;

}

itemNum = transform.FindChild("Content").childCount - 1;

contentParentHeight = conentRect.parent.GetComponent().sizeDelta.y;

conentSpacing = conentRect.GetComponent().spacing / 2;

itemHeight = textList[0].rectTransform.sizeDelta.y + conentSpacing;

if (itemNum % 2 == 0) conentLimit = (itemHeight + 5) / 2;

else conentLimit = 0;

conentRect.anchoredPosition = new Vector2(conentRect.anchoredPosition.x, conentLimit);

deltaX = textList[0].GetComponent().sizeDelta.x;

deltaY = textList[0].GetComponent().sizeDelta.y;

Invoke("ItemList", 0.05f);

}

/// 

/// 生成子项item

/// 

/// 子项数量

/// 子项最大值

void InstantiateData(int itemNum, int dat) {

GameObject go;

Text testObj = conentRect.FindChild("Text").GetComponent();

for (int i = dat - itemNum + 1; i <= dat; i++) {

go = Instantiate(testObj.gameObject, conentRect);

go.GetComponent().text = i.ToString();

go.name = i.ToString();

textList.Add(go.GetComponent());

ShowItem(true);

}

Destroy(conentRect.FindChild("Text").gameObject);

}

/// 

/// 是增加或减少

/// 

/// 

void ShowItem(bool isIncreaseOrdecrease) {

itemHeight_min = -itemHeight;

if (_itemtype == ItemType._day) itemHeight_max = -itemHeight * itemNum - 95;

else itemHeight_max = -itemHeight * itemNum;

if (isIncreaseOrdecrease) {

foreach (Text rectItem in textList) {

if (rectItem.GetComponent().anchoredPosition.y > itemHeight_min) {

print("+");

rectItem.transform.SetSiblingIndex((int)itemNum);

}

}

print(itemHeight_min);

} else {

foreach (Text rectItem in textList) {

if (rectItem.GetComponent().anchoredPosition.y 

print("-");

rectItem.transform.SetSiblingIndex(0);

}

}

print(itemHeight_max);

}

}

/// 

/// 渐变效果,改变大小,高亮显示

/// 

void ItemList() {

foreach (Text item in textList) {

float indexA = Mathf.Abs(item.GetComponent().position.y - targetRec.position.y);

float indexSc_scale = Mathf.Abs(curve_scale.Evaluate(indexA / contentParentHeight));

float indexSc_color = Mathf.Abs(curve_color.Evaluate(indexA / contentParentHeight));

if (indexA 

item.color = itemColor_hig;

switch (_itemtype) {

case ItemType._year: _year = int.Parse(item.text); break;

case ItemType._month: _month = int.Parse(item.text); break;

case ItemType._day: _day = int.Parse(item.text); break;

}

} else item.color = new Color(0, 0, 0, 1 - indexSc_color);

item.GetComponent().localScale = new Vector3(1 - indexSc_scale, 1 - indexSc_scale * 3, 1 - indexSc_scale);

//item.GetComponent().sizeDelta = new Vector2(deltaX - (deltaX * indexSc), deltaY - (deltaY * indexSc));

}

}

/// 

/// 获取int类型日期,并转换为指定格式

/// 

/// 

public static string GetDateInfo() { return _year + "-" + _month + "-" + _day; }

/// 

/// 纠正Conent位置

/// 

void UpdateEx() {

if (conentRect.anchoredPosition.y > conentLimit) {

ShowItem(true);

conentRect.anchoredPosition = new Vector2(conentRect.anchoredPosition.x, conentRect.anchoredPosition.y - itemHeight);

}

if (conentRect.anchoredPosition.y 

ShowItem(false);

conentRect.anchoredPosition = new Vector2(conentRect.anchoredPosition.x, conentRect.anchoredPosition.y + itemHeight);

}

}

/// 

/// 获取拖拽信息并改变Conent位置

/// 

/// 

void SetDraggedPosition(PointerEventData eventData) {

if (RectTransformUtility.ScreenPointToWorldPointInRectangle(conentRect, eventData.position, eventData.pressEventCamera, out newDragPos)) {

newDragPos = eventData.position;

if (Mathf.Abs(newDragPos.y - oldDragPos.y) >= itemHeight) {

if (newDragPos.y > oldDragPos.y) {

conentRect.anchoredPosition = new Vector2(conentRect.anchoredPosition.x, conentRect.anchoredPosition.y + itemHeight);

oldDragPos += new Vector3(0, itemHeight, 0);

ItemList();

} else {

conentRect.anchoredPosition = new Vector2(conentRect.anchoredPosition.x, conentRect.anchoredPosition.y - itemHeight);

oldDragPos -= new Vector3(0, itemHeight, 0);

ItemList();

}

}

}

}

/// 

/// 当开始拖拽

/// 

/// 

public void OnBeginDrag(PointerEventData eventData) {

oldDragPos = eventData.position;

}

public void OnDrag(PointerEventData eventData) {

SetDraggedPosition(eventData);

UpdateEx();

}

public void OnEndDrag(PointerEventData eventData) {

SetDraggedPosition(eventData);

UpdateEx();

}

}

照着来的话基本没什么问题

因为赶时间所以很多地方写的简单粗暴请谅解

如果调整元素大小或者间隙大小 需要改变itemHeight_min 和 itemHeight_max的值

他们分别为

itemHeight_min

1176379-20170612225917556-1946493637.png

itemHeight_max

1176379-20170612225955915-1636366617.png

也就是元素的最顶层和最底层的Y值

以上就是年月日选择器的具体步骤

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/302219.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

3秒取暖,超高颜值!冬日必备的大宇取暖器

天气越来越冷了&#xff0c;在小木冷的瑟瑟发抖的时候&#xff0c;朋友推荐了一台最新款的大宇取暖器&#xff0c;本来我怕是个鸡肋。但颜值确实是小木喜欢的呀&#xff0c;我就让怕冷的朋友先用用看&#xff0c;结果惊讶了&#xff01;这产品开了一会&#xff0c;朋友的小办公…

.Net Core with 微服务 - 架构图

上一次我们简单介绍了什么是微服务&#xff08;.NET Core with 微服务 - 什么是微服务&#xff09;。介绍了微服务的来龙去脉&#xff0c;一些基础性的概念。有大佬在评论区指出说这根本不是微服务。由于本人的能力有限&#xff0c;大概也只能理解到这个层次。先不管它到底是不…

PostgreSQL 的 target_list分析(五)

上文说到 ColumnRef 由于 a_expr 回溯到 c_expr。 其对应的 makeColumnRef 需要构建 ColumnRef 型Node, 看看 parsenodes.h&#xff1a; 00203 typedef struct ColumnRef 00204 { 00205 NodeTag type; 00206 List *fields; /* field names (Value st…

win10+tomcat+php+配置环境变量配置,Win10系统Tomcat环境变量配置方法

在Win10系统中配置Tomcat环境变量之前&#xff0c;需要先配置JAVA&#xff0c;之后就可以配置Tomcat环境了&#xff0c;网络上的教程要么太简单&#xff0c;不明觉厉&#xff0c;要么太复杂&#xff0c;笔者整理了以下思路&#xff0c;便是以下Win10系统Tomcat环境变量配置方法…

136个Python 机器学习知识点让你受益终生!

全世界只有3.14 % 的人关注了数据与算法之美如果村里通了网&#xff0c;那你一定知道【AI】人工智能。如果你会网上冲浪&#xff0c;那你一定看到过【ML】机器学习。小编在网上看到一个段子&#xff1a;ML派坐落美利坚合众山中&#xff0c;百年来武学奇才辈出&#xff0c;隐然成…

Linux内核中的内存屏障(转)

转自&#xff1a;http://www.linuxidc.com/Linux/2011-10/44623.htm 前言之前读了关于顺序一致性和缓存一致性讨论的文章&#xff0c;感觉豁然开朗。对linux内核中出现的种种同步和屏障&#xff0c;想做一点总结。 缓存一致性之前一直认为linux中很多东西是用来保证缓存一致性的…

微软Build2021今日召开,共同期待VS2022+.NET6!

Microsoft Build 2021全球开发者大会将至&#xff0c;将带来什么惊喜呢&#xff1f;去年Build 2020是第一次完全线上举办的Build大会&#xff0c;是第一次完全属于开发者的大会&#xff0c;几乎所有的新产品都是属于开发者&#xff0c;开发者是唯一的主角&#xff01;今年的Bui…

mysql group 条件,mysql - mysql group by,两个条件,限制1 - SO中文参考 - www.soinside.com...

我想为所有门票选择最早的活动日期。我在mysql中创建了这个查询“tixdate”视图(我用于其他目的)&#xff0c;它按票号排序记录&#xff0c;然后按eventdate排序。此视图如下所示&#xff1a;EventDate | Ticket2018-02-25 | 9982018-02-25 | 9982018-02-25 | 9982018-02-11 | …

Google和百度都无法替代的10大深网搜索引擎

全世界只有3.14 % 的人关注了数据与算法之美当我们想要搜索某些内容时&#xff0c;我们第一个想到的就是打开Google、百度或必应这类的搜索引擎。但针对有些内容&#xff0c;却是这些常规搜索引擎无法获取到的&#xff0c;那就是隐藏在深网的内容。据不完全统计&#xff0c;深网…

编写properties文件的Eclipse插件

2019独角兽企业重金招聘Python工程师标准>>> 分享一个不错的编写properties文件的Eclipse插件&#xff08;plugin&#xff09;&#xff0c;有了它我们在编辑一些简体中文、繁体中文等 Unicode文本时&#xff0c;就不必再使用native2ascii编码了。您可以通过Eclipse中…

让Dapper支持读写分离

在上一篇说了封装Dapper扩展方法为一个接口来支持Mock&#xff0c;接下来看看如何实现读写分离。其实定义两个接口&#xff0c;一个用来实现读&#xff0c;一个用来实现写。在读的接口里只有Query的方法&#xff0c;在写的接口里实现Query和Execute全量(通读写的库也是支持读的…

php显示前60个字,DEDECMS中怎么让文章标题栏突破60个字符

DEDECMS中怎么让文章标题栏突破60个字符&#xff1f;1、使用PHPMYADMIN 修改 MYSQL数据结构CODE: ALTER TABLE dede_archives CHANGE title title VARCHAR( 250 ) [Copy to clipboard]2、打开/dede/action_article_save.php找到39行 CODE: $title cn_substr($title,60); [Copy…

数学是理工基础,如何才能令人信服?

随着科技的快速发展&#xff0c;人工智能的重要性日渐显现。而数学知识蕴含着处理智能问题的基本思想与方法&#xff0c;是理解复杂算法的必备要素。在机器学习工作流程中&#xff0c;数学与代码高度交织在一起&#xff0c;代码通常可以根据数学直观地构建&#xff0c;甚至会共…

GNU make manual 翻译(四十三)

继续翻译 Another such occasion is when you want to generate prerequisites from source files automatically; the prerequisites can be put in a file that is included by the main makefile. This practice is generally cleaner than that of somehow appending …

巧用定时任务监控第三方组件是否正常

背景平常我们系统一般会涉及到一些使用第三方组件的情况&#xff0c;那么我们如何去监测&#xff0c;第一时间知道组件是否可用。或者是组件没报错&#xff0c;但是没法返回我们想要的数据。问题窥探一般做法是在调用的时候&#xff0c;如果是异常&#xff0c;就发出对应的报警…

php调用另一个php文件里的变量的值,thinkphp中一个方法调用另一个步骤的变量

thinkphp中一个方法调用另一个方法的变量//实例化上传类public function upload() {$upload new Upload();$upload->maxSize 10 * 1024 * 1024;$upload->exts array(jpg, jpeg, gif, txt,zip);$upload->savePath ./;$upload->hash false;$info $upload->u…

Win7玩CF,不能全屏的解决方法...

今天用自己的本本玩CF&#xff0c;发天竟然不能全屏&#xff0c;抓狂呀&#xff01; 在网上找了下&#xff0c;解决方法如下: 打开注册表&#xff0c;定位到: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\GraphicsDrivers\Configuration\AUO183C0_01_07D9_17^773484D7596…

EFCore之增删改查

1. 连接数据库通过依赖注入配置应用程序&#xff0c;通过startup类的ConfigureService方法中的AddDbContext将EFCore添加到依赖注入容器public void ConfigureServices(IServiceCollection services) {services.AddControllers();services.AddDbContext<OpenDbContext>(o…

matlab提示未定义wc,WooCommerce 教程:修复致命错误调用未定义的函数wc_get_order() - WooCommerce 微站...

我为客户开发了一个自定义支付网关插件&#xff0c;他们希望为 “鳕鱼”(货到付款)添加类似的方法。他希望增加一种称为 “交货卡” 的方法。我只是复制代码&#xff0c;将 PHP 添加到一个文件中&#xff0c;制作了一个插件&#xff0c;并给他插件 zip 文件。一切都很好&#x…

一堂儿童科学实验课引起的思考:数学和化学有什么关系?

全世界只有3.14 % 的人关注了数据与算法之美前段时间&#xff0c;我带侄子上了一堂化学课&#xff0c;回来之后&#xff0c;他一直意犹未尽找我的聊化学的事&#xff0c;期间他也问了身为数学专业的我一个交叉问题&#xff1a;叔&#xff0c;「数学」和「化学」有啥关系&#x…