cocostudio的bug(1)

今天有个女同事问我一个问题,两个cocostudio的ui同时addChild到一个layer上面,高层级的ui设置visible为false,低层级的ui设置的visible设置为true,然后低层级的ui上的点击事件不可点击,

我记得UIButton类中的触摸事件是调用UIWidget中的onTouchBegan方法,下面是点击事件的处理过程:

 

bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent)
{
    _hitted = false;
    if (isVisible() && isEnabled() && isAncestorsEnabled() && isAncestorsVisible(this) )
    {
        _touchBeganPosition = touch->getLocation();
        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;
}

 

如果visible为false的话,触摸事件不能触发,但是子节点的visible变量不为false,所以,子节点的触摸事件还是可以触发的,因此遮挡了低层次ui的触摸事件。这个是cocostudio源码开发者没有想得太周到的问题。

转载请注明出处,from 博客园HemJohn

posted on 2016-07-09 17:48  HemJohn  阅读(364)  评论(0编辑  收藏  举报

导航