ioscocos2d-iphonescrollccscrolllayer

Controlling touches in CCScrollLayer (cocos2d iOS)


I have a CCScrollLayer in my app which contains movable sprites (they can be dragged & dropped). The issue is that when dragging the sprites too far, the CCScrollLayer starts scrolling. I am trying to disable the CCScrollLayer from scrolling as long as I am dragging those sprites. The disabling works by using

[[CCTouchDispatcher sharedDispatcher] removeDelegate:sender];

I get the sender from method

- (void)scrollLayerScrollingStarted:(CCScrollLayer *)sender {
    //...
}

I cannot enable the CSScrollLayer again, tried with this but no result:

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:scrollLayer priority:0 swallowsTouches:NO];

I am using v1.0.1 (stable version)


Solution

  • You could subclass CCScrollLayer and add an enabled property boolean. Just override the touch methods that CCScrollLayer uses to start its sliding. For example

    -(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
    {
         if(self.enabled)
               return [super ccTouchBegan:touch withEvent:event];
         else
               return NO;
    }