zoukankan      html  css  js  c++  java
  • 嵌套ScrollView 左右滑动不影响上下滑动

    using UnityEngine;
    using System.Collections;
    
    public class UIMultDragScrollView : MonoBehaviour {
        public UIScrollView hScrollView;
        public UIScrollView vScrollView;
        public UIDragScrollView dragScrollView;
        public float directionTolerance = 0.2f;
        bool dragCheck = true; 
        public float direcDegle = 45;
        public void OnDrag(Vector2 delta)
        {
            int sd = -1;
            if (dragCheck)
            {
                dragCheck = false;
                sd = GetSwipeDirection(UICamera.currentTouch.delta, directionTolerance);
            }
            Debug.Log("swp"+sd);
            if( sd == 0)
            {
                Debug.Log("左");
                dragScrollView.scrollView = hScrollView;
                vScrollView.movement = UIScrollView.Movement.Custom;
                vScrollView.currentMomentum = new Vector3(0, 0);
                hScrollView.movement = UIScrollView.Movement.Horizontal;
                hScrollView.enabled = true;
                vScrollView.enabled = false;
                vScrollView.Press(false);
                hScrollView.Press(true);
               // hScrollView.Drag();
            }
            if (sd == 1)
            {
                Debug.Log("上");
                dragScrollView.scrollView = vScrollView;
                hScrollView.enabled = false;
                hScrollView.movement = UIScrollView.Movement.Custom;
                hScrollView.currentMomentum = new Vector3(0, 0);
                vScrollView.movement = UIScrollView.Movement.Vertical;
                vScrollView.enabled = true;
                hScrollView.Press(false);
                vScrollView.Press(true);
               // vScrollView.Drag();
            }
        }
        void OnPress(bool isDown)
        {
            if (isDown)
            {
                dragCheck = true;
            }
        }
        int GetSwipeDirection(Vector3 dir, float tolerance)
        {
            float minSwipeDot = Mathf.Clamp01(1.0f - tolerance);
            if (Mathf.Rad2Deg * (Mathf.Acos(Vector2.Dot(dir, Vector2.right) / (dir.magnitude * Vector2.right.magnitude))) <= direcDegle
                && Vector2.Dot(dir, Vector2.right) >= minSwipeDot)
                return 0;
            if (Mathf.Rad2Deg * (Mathf.Acos(Vector2.Dot(dir, -Vector2.right) / (dir.magnitude * (-Vector2.right).magnitude))) <= direcDegle
                && Vector2.Dot(dir, -Vector2.right) >= minSwipeDot)
                return 0;
            if (Mathf.Rad2Deg * (Mathf.Acos(Vector2.Dot(dir, Vector2.up) / (dir.magnitude * Vector2.up.magnitude))) <= 90 - direcDegle
                && Vector2.Dot(dir, Vector2.up) >= minSwipeDot)
                return 1;
            if (Mathf.Rad2Deg * (Mathf.Acos(Vector2.Dot(dir, -Vector2.up) / (dir.magnitude * (-Vector2.up).magnitude))) <= 90 - direcDegle
                && Vector2.Dot(dir, -Vector2.up) >= minSwipeDot)
                return 1;
            return -1;
        }
    }
    

      

  • 相关阅读:
    ASP.NET C# 邮件发送全解
    .NET应用框架架构设计实践 概述
    给大家推荐几个国外IT技术论坛
    IIS 内部运行机制
    大型网站后台架构的Web Server与缓存
    CMD 获得当前目录命令
    html之marquee详解
    sharepoint 富文本编辑器
    C# 将数据导出到Execl汇总(C/S和B/S)
    更改应用程序池的密码 (Windows SharePoint Services)
  • 原文地址:https://www.cnblogs.com/hersen/p/3946390.html
Copyright © 2011-2022 走看看