0

I try to add CCScrollView with paging (cocos2d- iphone v3.0). But it's not working. It doesn't call any delegate methods (for example scrollViewDidScroll:).

CCNode *cards = [CCNode node];
for (int i = 0 ; i < 3; i++) {
    CCLabelTTF *label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"label %d", i] fontName:@"Arial" fontSize:24];
    label.color = [CCColor redColor];
    label.position = ccp(winSize.width * i + winSize.width * 0.5 , winSize.height * 0.5);
    [cards addChild:label];
}
self.scrollView = [[CCScrollView alloc] initWithContentNode:cards];
self.scrollView.contentSizeType = CCSizeTypeNormalized;
self.scrollView.contentSize = CGSizeMake(3, 1);
self.scrollView.pagingEnabled = YES;
self.scrollView.delegate = self;
self.scrollView.position = CGPointZero;
self.scrollView.anchorPoint = CGPointZero;
[self addChild:self.scrollView];
Kikiki
  • 71
  • 5

1 Answers1

0

You actually need to set the contentSize of the contentNode of the scrollView as opposed to the contentSize of the scrollView.

In CCScrollView.h

@property (nonatomic,strong) CCNode* contentNode;

So you should replace this part of the code:

self.scrollView.contentSizeType = CCSizeTypeNormalized;
self.scrollView.contentSize = CGSizeMake(3, 1);

With this:

self.scrollView.contentNode.contentSizeType = CCSizeTypeNormalized;
self.scrollView.contentNode.contentSize = CGSizeMake(3, 1);
lucianomarisi
  • 1,552
  • 11
  • 24
  • It doesn't help :( As I understand, problem isn't in delegates methods. Even GestureRecognizers methods don't call. I mean handlePan: and handleTap:. But I don't know, what is wrong – Kikiki May 31 '14 at 14:44
  • My guess is that there is something else in your project interfering with this, since I have tested your code with my change in a new project and everything works fine. – lucianomarisi May 31 '14 at 14:56
  • Yes, thank. I inherited parent from CCNode, and when I change it to CCScene, scrollView works correctly. – Kikiki May 31 '14 at 17:12