当前位置:网站首页>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
边栏推荐
- 并发场景下的死锁原因及规避解决方法
- 爬虫系列:读取文档
- How to judge an IP is a crawler
- How is the commission for online account opening reduced?Is it safe to open an account with an online account manager?
- 2022-08-08:给定一个数组arr,表示从早到晚,依次会出现的导弹的高度。 大炮打导弹的时候,如果一旦大炮定了某个高度去打,那么这个大炮每次打的高度都必须
- 6.8.3 sigqueue函数
- JQGrid通过json请求nodejs数据,表格信息保存在mysql数据库中
- IPv6 私有地址
- 奈雪在亏损,背后供应商赢麻了
- 2020-03-09
猜你喜欢
随机推荐
DCM: 中间件家族迎来新成员
爬虫视频教学:网页数据抓取
世界经济和金融秩序再定义 | 零数科技受邀出席第三届世界金融论坛
2020-03-09
Oxylabs线上研讨会:网站抓取解决方案实操
二叉搜索树中求得给定元素的下界
基于阿里云的基础架构设施保障(一)IAAS云计算
How pyspark works
嵌入式开发:提示和技巧——C 语言中要避免的8个保留字
音视频技术开发周刊 | 257
"New Infrastructure of Cultural Digital Strategy and Ecological Construction of Cultural Art Chain" was successfully held
买股票要选择哪家证券公司更好?网上客户经理开户安全吗
Contextual Transformer Networks for Visual Recognition paper and code analysis
AutoAssign论文解析
如何判断一个 IP 是爬虫
2.5W 字详解线程与锁了,面试随便问!!
二叉堆的建立
2020-03-09
U disk cannot be displayed on computer
论网络安全的重要性