<legend id='QzJqs'><style id='QzJqs'><dir id='QzJqs'><q id='QzJqs'></q></dir></style></legend>
<i id='QzJqs'><tr id='QzJqs'><dt id='QzJqs'><q id='QzJqs'><span id='QzJqs'><b id='QzJqs'><form id='QzJqs'><ins id='QzJqs'></ins><ul id='QzJqs'></ul><sub id='QzJqs'></sub></form><legend id='QzJqs'></legend><bdo id='QzJqs'><pre id='QzJqs'><center id='QzJqs'></center></pre></bdo></b><th id='QzJqs'></th></span></q></dt></tr></i><div id='QzJqs'><tfoot id='QzJqs'></tfoot><dl id='QzJqs'><fieldset id='QzJqs'></fieldset></dl></div>

      <tfoot id='QzJqs'></tfoot>
        <bdo id='QzJqs'></bdo><ul id='QzJqs'></ul>

    1. <small id='QzJqs'></small><noframes id='QzJqs'>

    2. CCScrollView 滚动和触摸事件永远不会触发

      CCScrollView scroll and touch events never firing(CCScrollView 滚动和触摸事件永远不会触发)
          <bdo id='vt6vd'></bdo><ul id='vt6vd'></ul>
            <tfoot id='vt6vd'></tfoot>

            <small id='vt6vd'></small><noframes id='vt6vd'>

            <i id='vt6vd'><tr id='vt6vd'><dt id='vt6vd'><q id='vt6vd'><span id='vt6vd'><b id='vt6vd'><form id='vt6vd'><ins id='vt6vd'></ins><ul id='vt6vd'></ul><sub id='vt6vd'></sub></form><legend id='vt6vd'></legend><bdo id='vt6vd'><pre id='vt6vd'><center id='vt6vd'></center></pre></bdo></b><th id='vt6vd'></th></span></q></dt></tr></i><div id='vt6vd'><tfoot id='vt6vd'></tfoot><dl id='vt6vd'><fieldset id='vt6vd'></fieldset></dl></div>
              <tbody id='vt6vd'></tbody>
          1. <legend id='vt6vd'><style id='vt6vd'><dir id='vt6vd'><q id='vt6vd'></q></dir></style></legend>

                本文介绍了CCScrollView 滚动和触摸事件永远不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我找不到任何有用的教程或关于如何使用 CCScrollView 的说明.我有一个精灵和标签的网格布局(列出 iOS 游戏的成就).屏幕上放不下的东西太多了,所以我希望用户能够滚动.

                I can't find any helpful tutorials or explanation on how to use a CCScrollView. I have a grid-layout of sprites and labels (listing achievements for an iOS game). There are more than can fit on the screen so I want the user to be able to scroll.

                要滚动,用户将向上滑动/平移,以显示较低的精灵等.

                To scroll, the user would swipe/pan upwards, to reveal the sprites etc which are lower.

                我找到了一些代码示例,它们似乎表明您只需将内容节点添加到滚动节点,剩下的就交给它了.

                I've found a few code samples and they seem to indicate you just need to add your content node to the scroll node and it will take care of the rest.

                它似乎不起作用.没有滚动,滚动层上的平移/触摸事件似乎永远不会触发.我在同一个孩子(滚动视图的兄弟)上的关闭按钮不再起作用.

                It doesn't seem to work. There's no scroll, and the pan/touch events on the scroll layer never seem to fire. The close button I have at the same child (sibling to the scroll view) no longer works as well.

                我没有使用 SpriteBuilder.

                I'm not using SpriteBuilder.

                // Node to hold all sprites/labels
                scrollContents = [CCNode node];
                
                // I add a bunch of sprites/labels in a grid view
                for( NSString *key in badgeKeys ){
                
                    // logic to load the sprite would be here
                
                    CCSprite *badge = [CCSprite spriteWithSpriteFrame:frame];
                    badge.positionType = CCPositionTypeNormalized;
                    badge.position = ccp(xPos,yPos);
                    [scrollContents addChild:badge];
                
                    // some logic to increment x/y position logic, for grid layout
                
                }
                
                // Scroll view
                scrollView = [[CCScrollView alloc] initWithContentNode:scrollContents];
                scrollView.horizontalScrollEnabled = NO;
                scrollView.verticalScrollEnabled = YES;
                [scrollView setBounces:NO];
                
                // My sprites never even show unless I manually set this
                scrollContents.contentSize = CGSizeMake(self.contentSize.width,960);
                NSLog(@"scrollContents contentsize: %f %f", scrollContents.contentSize.width,scrollContents.contentSize.height);
                
                [self addChild:scrollView];
                

                推荐答案

                好的,这是一个工作示例(我解构了我的部分代码,为您提供一个完整工作的代码示例),其中包含实时"按钮的滚动菜单.我刚刚测试了这个解构",它有效

                ok, here is a working example (i deconstructed part of my code to give you a fully working code sample) of a scrolling menu with 'live' buttons inside. I just tested this 'deconstruction' , it works

                - (void) scrollingMenuWithCharmsTest {
                
                //    setup something to scroll
                
                GameInventory *gi = [GameInventory sharedGameInventory];
                while (gi.armorCharms.count < 20) {
                    [gi addArmorCharm:[ArmorCharm createRandomArmorCharm]];
                }
                
                CCNode *contentNode = [self charmsContentNodeFor:gi.armorCharms
                                                     showEquiped:NO
                                         spacingBetweenMenuItems:8
                                                          target:self
                                                        selector:@selector(onArmorCharmSelected:)];
                
                // setup a clipping node to crop out the CCScrollingMenu
                
                
                CCNodeColor *ccn = [CCNodeColor nodeWithColor:[CCColor blackColor] width:180 height:200];
                ccn.anchorPoint = ccp(0, 0);
                CCClippingNode *cn = [CCClippingNode clippingNodeWithStencil:ccn];
                cn.alphaThreshold = 0.05f;
                [self addChild:cn];
                cn.inverted            = NO;
                cn.positionInPointsV   = ccp(50, 50);
                cn.anchorPoint         = ccp(0, 0);
                cn.contentSizeInPoints = CGSizeMake(180, 200);
                
                // setup scrolling menu
                
                CCScrollView * bsm = [[CCScrollView alloc] initWithContentNode:contentNode];
                bsm.contentSize=CGSizeMake(180,200);
                
                [cn addChild:bsm];
                bsm.position                = ccp(0, 0);
                bsm.bounces                 = YES;
                bsm.pagingEnabled           = NO;
                bsm.verticalScrollEnabled   = YES;
                bsm.horizontalScrollEnabled = NO;
                
                bsm.contentSizeInPoints = CGSizeMake(180, 200); // inPoints only after the node has a parent
                
                for (CharmAbstractBoxMenuItem *lmi in bsm.contentNode.children) {
                    TRACE(@"item %@ is at %@", lmi.item.description, NSStringFromCGPoint(lmi.positionInPointsV));
                }
                TRACE(@"number of pages : %i", bsm.numVerticalPages);
                
                }
                
                - (CCNode *)charmsContentNodeFor:(NSDictionary *)keyedItems
                                     showEquiped:(BOOL)isShowEquiped
                         spacingBetweenMenuItems:(float)inSpacing
                                          target:(id)inTarget
                                        selector:(SEL)inSelector {
                
                NSSortDescriptor *sortOrder  = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES];
                NSArray          *sortedKeys = [[keyedItems allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortOrder]];
                
                float initialY = 0;
                float currentY = initialY;
                
                NSUInteger      itemNumber   = 0;
                CGFloat         width        = 0;
                CGFloat         height       = 0;
                CCNode          *contentNode = [CCNode node];
                for (NSUInteger loopi        = 0; loopi < [sortedKeys count]; loopi++) {
                    NSString      *key = [sortedKeys objectAtIndex:loopi];
                    CharmAbstract *ci  = [keyedItems objectForKey:key];
                
                    if (ci) {
                        CharmAbstractBoxMenuItem *cmi = [CharmAbstractBoxMenuItem itemBoxFor:ci
                                                                                      target:inTarget
                                                                                    selector:inSelector
                        ];
                
                        cmi.toolTip  = ci.toolTip;
                        cmi.position = ccp(deviceOffset(0), currentY);
                        cmi.key      = key;
                        [contentNode addChild:cmi z:0 name:[NSString stringWithFormat:@"%li", (long) itemNumber]];
                
                        currentY += cmi.contentSizeInPoints.height + inSpacing;
                        itemNumber++;
                        if (cmi.contentSize.width > width) width = cmi.contentSize.width;
                        height += cmi.contentSize.height;
                        if (loopi < sortedKeys.count - 1) height += inSpacing;
                    }
                    else {
                        MPLOG(@"*** Key [%@] yielded no items.", key);
                    }
                
                }
                contentNode.contentSizeType = CCSizeTypePoints;
                contentNode.contentSize     = CGSizeMake(width, height);
                return contentNode;
                
                }
                

                一些注意事项:

                • 我为您提供了我的构建内容节点"例程,以便您了解位置和大小的来龙去脉.
                • 我的 charmBoxMenuItems 派生自 'CCButton' 并且很热......在此代码片段的完整版本中,我扩展了 CCScrollView 以防止按钮在裁剪区域之外变得热"(尽管它们已从视图中裁剪出来,默认情况下,它们仍然是可见的",并且可以在裁剪区域上方或下方发生随机点击时做出响应).
                • 要使用模板裁剪节点,您需要在 setupCocos2dWithOptions 行中添加:

                • i gave you my 'build content node' routine so you know the ins and outs of positions and sizes.
                • my charmBoxMenuItemss derive from 'CCButton' and are hot ... In the full version of this code snippet, i extended CCScrollView to prevent the buttons from being 'hot' outside the crop area (although they are cropped out from view, they are still 'visible' by default, and could respond when a random tap occurs above or below the crop area).
                • For clipping node with stencil, you need to add this in your setupCocos2dWithOptions line:

                CCSetupDepthFormat : [NSNumber numberWithUnsignedInt:GL_DEPTH24_STENCIL8_OES]

                CCSetupDepthFormat : [NSNumber numberWithUnsignedInt:GL_DEPTH24_STENCIL8_OES]

                这篇关于CCScrollView 滚动和触摸事件永远不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                Resume game cocos2d(恢复游戏 cocos2d)
                Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  <tbody id='x1fYb'></tbody>

                <small id='x1fYb'></small><noframes id='x1fYb'>

                • <i id='x1fYb'><tr id='x1fYb'><dt id='x1fYb'><q id='x1fYb'><span id='x1fYb'><b id='x1fYb'><form id='x1fYb'><ins id='x1fYb'></ins><ul id='x1fYb'></ul><sub id='x1fYb'></sub></form><legend id='x1fYb'></legend><bdo id='x1fYb'><pre id='x1fYb'><center id='x1fYb'></center></pre></bdo></b><th id='x1fYb'></th></span></q></dt></tr></i><div id='x1fYb'><tfoot id='x1fYb'></tfoot><dl id='x1fYb'><fieldset id='x1fYb'></fieldset></dl></div>

                      <tfoot id='x1fYb'></tfoot>
                        <bdo id='x1fYb'></bdo><ul id='x1fYb'></ul>
                      • <legend id='x1fYb'><style id='x1fYb'><dir id='x1fYb'><q id='x1fYb'></q></dir></style></legend>