当前位置:网站首页>Unity 双生ScrollView滑动冲突问题
Unity 双生ScrollView滑动冲突问题
2022-08-08 22:07:00 【w0100746363】
上一篇解决了循环左右翻页的问题,如果子节点中也存在ScrollView的话,翻到该子节点时左右滑动就不生效了,得解决它们的冲突。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ChildScrollView : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
/// <summary>
/// 外层被拦截需要正常拖动的ScrollRect
/// </summary>
public ScrollRect anotherScrollRect;
private ScrollRect thisScrollRect;
void Start()
{
thisScrollRect = GetComponent<ScrollRect>();
if (anotherScrollRect == null)
anotherScrollRect = GetComponentsInParent<ScrollRect>()[1];
}
public void OnBeginDrag(PointerEventData eventData)
{
anotherScrollRect.OnBeginDrag(eventData);
}
public void OnDrag(PointerEventData eventData)
{
anotherScrollRect.OnDrag(eventData);
float angle = Vector2.Angle(eventData.delta, Vector2.up);
//判断拖动方向,防止水平与垂直方向同时响应导致的拖动时整个界面都会动
if (angle > 45f && angle < 135f)
{
thisScrollRect.enabled = false;
anotherScrollRect.enabled = true;
}
else
{
anotherScrollRect.enabled = false;
thisScrollRect.enabled = true;
}
}
public void OnEndDrag(PointerEventData eventData)
{
anotherScrollRect.OnEndDrag(eventData);
//拖动结束后调用外层ScrollView的回弹效果
if (anotherScrollRect.enabled)
anotherScrollRect.GetComponent<MainScrollView>().ChildScrollEndDrag(eventData);
anotherScrollRect.enabled = true;
thisScrollRect.enabled = true;
}
}
把脚本挂到子节点的ScrollView上就可以了。
转载:https://blog.csdn.net/qq_35037137/article/details/88537421
边栏推荐
猜你喜欢
17 [2D conversion 3D conversion browser private prefix]
奈雪在亏损,背后供应商赢麻了
实时爬虫实例讲解
爬虫视频教学:网页数据抓取
基于阿里云的基础架构设施保障(一)IAAS云计算
股市预测,销量预测,病毒传播...一个时间序列建模套路搞定全部!
零数科技向海南省委书记汇报数字金融创新
"New Infrastructure of Cultural Digital Strategy and Ecological Construction of Cultural Art Chain" was successfully held
Oxylabs线上研讨会:网站抓取解决方案实操
Zero Digital Reports Digital Financial Innovation to the Secretary of Hainan Provincial Party Committee
随机推荐
基于.NET6、FreeSql、若依UI、LayUI、Bootstrap构建插件式的CMS
为什么要做LiveVideoStack课程?
如何寻找竞争情报发挥企业优势
记录每天学习的新知识: Room
战投部都没了的字节,买了一家高端妇幼医院
IPv6 private address
Likou Question of the Day----Maximum Average of Subarrays
Mysql汉字乱码的问题
Matlab to download
测试/开发程序员,如何跳出技术瓶颈?一年两年......
微服务架构的核心关键点
远程调试为何要亲历现场,也许也可以这样解决
网上开户佣金是怎么调低的?网上客户经理开户安全吗
今日头条10岁了,它会成为下一个QQ么?
ZERO Technology "Chain on the South"——deeply cultivated in the field of digital finance
2020-03-09
2020-03-09
U盘无法在电脑上显示
scala排序,排序,排序,sortBy sortWith
零数科技“链上海南”——深耕数字金融领域