嵌套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;
    }
}

  

时间: 2024-10-14 07:14:41

嵌套ScrollView 左右滑动不影响上下滑动的相关文章

ScrollView中嵌套ScrollView或ListView并且内部ScrollView或ListView也可滑动

1.ScrollView中嵌套ScrollView并且内部ScrollView也可滑动 (1)ScrollView继承类 public class InnerScrollView extends ScrollView { Handler handler; public ScrollView parentScrollView; public InnerScrollView(Context context, AttributeSet attrs) { super(context, attrs); h

解决ViewPage中嵌套有ListView或者滑动手势等造成滑动的冲突

public class ViewPagerCompat extends ViewPager { //mViewTouchMode表示ViewPager是否全权控制滑动事件,默认为false,即不控制 private boolean mViewTouchMode = false; public ViewPagerCompat(Context context, AttributeSet attrs) { super(context, attrs); } public void setViewTou

Android仿小米商城商品详情界面UI,ScrollView嵌套ScrollView/WebView/ListView

最近公司没事,研究了下多嵌套滚动组件的事件分发,虽然以前也接触过,但都是拿网上的用,也是特别简单的,正好朋友也需要,就研究了下 这个Demo也不是很完善,放上来也是让各位大牛给指点一下,优化优化 使用情景: 小米商城商品详情界面,界面看似ScrollView,但当正常滚动到底部时,提示继续上拉显示更多详情,上拉后直接滚动到第二屏,第二屏是个ViewPager,ViewPager里面的各个pager有的是WebView有的是ListView,有的是ScrollView,一开始想想就特别头晕,后来理

ScrollView如何嵌套ScrollView

android开发中ScrollView嵌套ScrollView是android最常用的功能,众所周知,android 里两个相同方向的ScrollView是不能嵌套的,那要是有这样的需求怎么办? 目前做的这个只支持两个ScrollView嵌套,两个以上还有待改进,能套两个就已经能满足很多需求了,呵呵,另外现在只做了纵向scrollview的支持,横向的还没做 package com.example.easy.view; /** * Created by admin on 2016/5/10.

ListView嵌套ScrollView后,设置dividerHeight属性后高度计算

当我们需要在listView外层嵌套ScrollView,这样两个scroll滚动效果会产生相互影响,为了避免这个,我们通常是禁止listView滚动, 把ListView总高度计算出来,完全显示. 计算listView的总高度只需要自定义一个mylistView继承listView,重写onMeasure(...)方法就搞定了. @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { i

Android 为什么我的PullListView只能向下滑动,不能向上滑动加载更多???

============问题描述============ Android 为什么我的PullListView只能向下滑动,不能向上滑动加载更多??? ============解决方案1============ mode模式,你可以看看官方api

Android ScrollView嵌套ScrollView滚动的问题解决办法

引用:http://mengsina.iteye.com/blog/1707464 http://fenglog.com/article.asp?id=449 Android ScrollView嵌套ScrollView滚动的问题解决办法 原文地址:http://trivedihardik.wordpress.com/2011/09/19/scrollview-inside-scrollview-scrolling-problem/ 搞技术的多少看的懂E文,也不翻译了. While design

实现滑动屏幕与底层滑动指标适配

首先是封装好的滑动指标类,具体首先创建一个画图类:SliderIndicator类,该类代码如下: //SliderIndicator.h #include "cocos2d.h" #include "ui/CocosGUI.h" USING_NS_CC; class SliderIndicator:public ui::Layout { public: CREATE_FUNC(SliderIndicator); virtual bool init(); CC_SY

滑动跟随手指横向滑动

浪去项目有个头图滑动横向滑动的需求,故写次demo <!DOCTYPE html> <html> <head> <title>滑动跟随手指横向滑动</title> <style type="text/css"> .spirit { /* 方块的class名称*/ position: absolute; width: 50px; height: 50px; background-color: red; } </