我在创建的时候setTouchEnabled(false);之后还是会触发touch事件。
UILayer* uiPlay = UILayer::create();
uiPlay->addWidget(dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("UI_Play/UI_Play.json")));
this->addChild(uiPlay, 21, eUI_Play);
UIButton* BtnPause =dynamic_cast<UIButton*>(uiPlay->getWidgetByName( "BtnPause"));
BtnPause->addTouchEventListener(this, toucheventselector(HelloWorld::btnPauseTouchEvent));
UIButton* BtnLeft =dynamic_cast<UIButton*>(uiPlay->getWidgetByName( "BtnLeft"));
BtnLeft->addTouchEventListener(this, toucheventselector(HelloWorld::btnLeftTouchEvent));
UIButton* BtnRight =dynamic_cast<UIButton*>(uiPlay->getWidgetByName( "BtnRight"));
BtnRight->addTouchEventListener(this, toucheventselector(HelloWorld::btnRightTouchEvent));
uiPlay->setVisible(false);
UILayer* uiPause = UILayer::create();
uiPause->addWidget(dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("UI_Pause/UI_Pause.json")));
this->addChild(uiPause, 20, eUI_Pause);
UIButton* BtnContinue =dynamic_cast<UIButton*>(uiPause->getWidgetByName( "BtnContinue"));
BtnContinue->addTouchEventListener(this, toucheventselector(HelloWorld::btnContinueTouchEvent));
UIButton* BtnRestart =dynamic_cast<UIButton*>(uiPause->getWidgetByName( "BtnRestart"));
BtnRestart->addTouchEventListener(this, toucheventselector(HelloWorld::btnRestartTouchEvent));
UIButton* BtnStop =dynamic_cast<UIButton*>(uiPause->getWidgetByName( "BtnStop"));
BtnStop->addTouchEventListener(this, toucheventselector(HelloWorld::btnStopTouchEvent));
uiPause->setVisible(false);
UILayer* uiStart = UILayer::create();
uiStart->addWidget(dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("UI_Start/UI_Start.json")));
this->addChild(uiStart, 42, eUI_Start);
UIButton* BtnStart = dynamic_cast<UIButton*>( uiStart->getWidgetByName( "BtnStart" ));
BtnStart->addTouchEventListener(this, toucheventselector(HelloWorld::btnStartTouchEvent));
uiStart->setVisible(true);
上面这段是在uiInit()里的,然后:
/////////////////////////////
// 3. add your codes below...
this->uiInit();
dynamic_cast<UILayer*>(this->getChildByTag(eUI_Play))->setTouchEnabled(false);
dynamic_cast<UILayer*>(this->getChildByTag(eUI_Pause))->setTouchEnabled(false);
还是不行