diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index dff5f32bd8..c88e3b17f0 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -360,19 +360,18 @@ void CheckBox::setupFrontCrossDisableTexture() _frontCrossDisabledRendererAdaptDirty = true; } - -void CheckBox::releaseUpEvent() +void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent) { - Widget::releaseUpEvent(); - if (_isSelected) { setSelected(false); + Widget::onTouchEnded(touch, unusedEvent); unSelectedEvent(); } else { setSelected(true); + Widget::onTouchEnded(touch, unusedEvent); selectedEvent(); } } @@ -391,6 +390,12 @@ void CheckBox::onPressStateChangedToNormal() _backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); _frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); + + if (_isSelected) + { + _frontCrossRenderer->setVisible(true); + _frontCrossRendererAdaptDirty = true; + } } void CheckBox::onPressStateChangedToPressed() @@ -433,6 +438,12 @@ void CheckBox::onPressStateChangedToDisabled() _frontCrossRenderer->setVisible(false); _backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); _frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); + + if (_isSelected) + { + _frontCrossDisabledRenderer->setVisible(true); + _frontCrossDisabledRendererAdaptDirty = true; + } } void CheckBox::setZoomScale(float scale) @@ -453,18 +464,6 @@ void CheckBox::setSelected(bool selected) } _isSelected = selected; _frontCrossRenderer->setVisible(_isSelected); - - if (_isSelected) - { - if (_bright) { - _frontCrossRenderer->setVisible(true); - _frontCrossRendererAdaptDirty = true; - } - else { - _frontCrossDisabledRenderer->setVisible(true); - _frontCrossDisabledRendererAdaptDirty = true; - } - } } bool CheckBox::isSelected()const diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h index ae3df31fa0..aa626c1a98 100644 --- a/cocos/ui/UICheckBox.h +++ b/cocos/ui/UICheckBox.h @@ -232,6 +232,7 @@ public: //override functions + virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; virtual Size getVirtualRendererSize() const override; virtual Node* getVirtualRenderer() override; virtual std::string getDescription() const override; @@ -277,8 +278,6 @@ protected: void selectedEvent(); void unSelectedEvent(); - virtual void releaseUpEvent() override; - virtual void onSizeChanged() override; void backGroundTextureScaleChangedWithSize();