0

I'm using a CCScrollView in a pop-up tab which overlaps some existing controls on the screen. The problem is that although the CCScrollView is responding correctly to touches, the touches are not being swallowed, so that the controls underneath it respond to them also.

I verified that the control is registering itself as a targeted delegate with the TouchDispatcher and I actually put a breakpoint on the "return true" in CCScrollView::ccTouchBegan and watched it hit it, but the touches were still passed to the controls underneath also.

I couldn't find much on this on SO, but I found that someone had this problem some time ago in the regular cocos2d:

http://www.cocos2d-iphone.org/forums/topic/making-ccscrollview-swallow-touches-but-still-scroll/

unfortunately the only answer there didn't help.

I feel like I must be missing something simple but I'm just about at my wit's end. Any advice on what I'm doing wrong?

2 Answers 2

2

I came back to the problem after a break and after some renewed frustration I found that CCScrollView actually really wants this behavior. From lines 133-136 of CCScrollView.cpp:

void CCScrollView::registerWithTouchDispatcher()
{
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, CCLayer::getTouchPriority(), false);
}

That false at the end is of course the culprit.

I am completely in the dark why anyone would want this as the default behavior, but at least my code works now.

0

MyLayer::MyLayer()

{

CCWidgetLayout* widgetLayout = CCWidgetLayout::create();

addChild(widgetLayout);

CCScroll* scroll= = CCScroll::create(CCSize(480,800));

    scroll->setPosition(ccp(480,800));
    scroll->setScrollSelector(this, scroll_selector(MyLayer::onScrolling));
    scroll->setDirection(eScrollDirectionVertical);
    widgetLayout->addChild(scroll);

      sprite = CCSprite::create("scrollcontent.png");   
      scroll->setContainerSize(sprite->getContentSize());
      scroll->getContainer()->addChild(sprite);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.