zoukankan      html  css  js  c++  java
  • 解决scrollview上的menu拖动问题以及menu item在可视区外仍能触发的问题

    最近在做项目发现一个让人很头疼的问题

    qiick-3.5 引擎 lua 版本

    一 问题如下:

      ① 在Cocostudio中做界面 使用 scrollview 控件 ,然后 scrollview 控件的 item 点击事件 是 ImageView 

      ② 当拖动 scrollview 的时候会 触发 item 的点击事件,照成体验及其的差。

     

    二 解决方案

      ① 重写 imageview的 点击事件 添加一个成员变量 

      ② 实现基本原理:

        1.首先判断当前imageview 是否接收了吞噬事件。如果不吞噬事件然后再进行事件阻断操作。

        2.将点击的起始坐标 转化成世界坐标 然后对比 点击结束后的坐标 如果 位置不一致 就不派发 点击事件

    public:

      virtual bool onTouchBegan(Touch *touch, Event *unusedEvent);

        virtual void onTouchEnded(Touch *touch, Event *unusedEvent);

    private:

        Vec2 _touchBeganWorldPosition;

     ② 方法实现

    bool ImageView::onTouchBegan(Touch *touch, Event *unusedEvent)

    {

        _hitted = false;

        if (isVisible() && isEnabled() && isAncestorsEnabled() && isAncestorsVisible(this) )

        {

            _touchBeganPosition = touch->getLocation();

            bool isSwallowTouches = this->isSwallowTouches();

            if (!isSwallowTouches)

            {

                _touchBeganWorldPosition = convertToWorldSpace(_touchBeganPosition);

            }

            

            if(hitTest(_touchBeganPosition) && isClippingParentContainsPoint(_touchBeganPosition))

            {

                _hitted = true;

            }

        }

        if (!_hitted)

        {

            return false;

        }

        setHighlighted(true);

        

        /*

         * Propagate touch events to its parents

         */

        if (_propagateTouchEvents)

        {

            this->propagateTouchEvent(TouchEventType::BEGAN, this, touch);

        }

        

        pushDownEvent();

        return true;

    }

      

    void ImageView::onTouchEnded(Touch *touch, Event *unusedEvent)

    {

        _touchEndPosition = touch->getLocation();

        

        bool isSwallowTouches = this->isSwallowTouches();

        if(!isSwallowTouches){

            Vec2 newWorldPos = convertToWorldSpace(_touchEndPosition);

            const static float kMenuMinMove = 2;

            if (fabs(newWorldPos.x - _touchBeganWorldPosition.x)>kMenuMinMove || fabs(newWorldPos.y-_touchBeganWorldPosition.y)>kMenuMinMove)

            {

                return;

            }

        }

        /*

         * Propagate touch events to its parents

         */

        if (_propagateTouchEvents)

        {

            this->propagateTouchEvent(TouchEventType::ENDED, this, touch);

        }

        

        bool highlight = _highlight;

        setHighlighted(false);

        

        if (highlight)

        {

            releaseUpEvent();

        }

        else

        {

            cancelUpEvent();

        }

    }

    用了以上的方法后,效果实现。

    方法参考网址:http://blog.csdn.net/n5/article/details/38266855

        

  • 相关阅读:
    将文献的bibtex引用格式批量转换为bibitem格式参考文献
    ubuntu下webbench作网站压力测试教程【webbench安装】
    Windows10安装虚拟机VMware并且安装ubuntu16系统
    ubuntu 16.04系统下解决MySQL 的root用户重置密码问题
    elementui 中 日期时间插件 结束时间大于开始时间
    SqlDbType 与 .Net 数据类型对照表
    可用的datatable转换成List<T>
    【beyond compare4 秘钥】亲测4.1.6可用
    winform 自定义控件圆按钮插件
    net framework 4.0 wcf发布到IIS
  • 原文地址:https://www.cnblogs.com/cci8go/p/4748711.html
Copyright © 2011-2022 走看看