CCScrollView 不接收触摸 (Cocos2d V 3.0)



我尝试添加带有分页的CCScrollView(cocos2d- iphone v3.0(。但它不起作用。它不调用任何委托方法(例如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];

您实际上需要设置scrollView contentNodecontentSize,而不是scrollViewcontentSize

CCScrollView.h

@property (nonatomic,strong) CCNode* contentNode;

所以你应该替换这部分代码:

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

有了这个:

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

相关内容

  • 没有找到相关文章

最新更新