天天看點

cocostudio UI 筆記

cocostudio UI 筆記

經常會遇到這樣的情況:

(1)layout1想要接受觸摸事件

(2)layout1的子視圖layout2不接受觸摸事件,但layout2裡的button接受觸摸事件。

解決辦法:

讓layout->setEnabled(true);

layout->addTouchEventListener(CC_CALLBACK_2(ChapterLayer::touchEvent, this));

給layout加個觸摸事件,讓它去吞噬layout的低優先級事件。

layout裡有2個方法是和觸摸相關的

(1)setTouchEnabled,預設_touchEnabled(false),

    virtual void setTouchEnabled(bool enabled);

(2)setEnebled, 預設_enabled ( true ),

    virtual void setEnabled(bool enabled);

我個人感覺這兩個方法在功能上重疊了

同樣都是控制能否接受到觸摸事件,但後者對EventListener進行了封裝,是以誕生了setEnebled