Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当项目靠近屏幕边缘放置时,其触摸精度较低_Ios_Cocos2d Iphone_Ios6_Iphone 5_Ccmenuitem - Fatal编程技术网

Ios 当项目靠近屏幕边缘放置时,其触摸精度较低

Ios 当项目靠近屏幕边缘放置时,其触摸精度较低,ios,cocos2d-iphone,ios6,iphone-5,ccmenuitem,Ios,Cocos2d Iphone,Ios6,Iphone 5,Ccmenuitem,当我尝试在iTouch 5上构建和运行我的游戏(基于Cocos2d 1.0.1,内置于Xcode 4.5和iOS 6.0 SDK)时,我发现CmenuItems行为不正常:当menuitem与屏幕边缘相邻时,边缘边框似乎不太容易在内部被点击以响应触摸事件(对不起,我的表达不好) 为了演示这个问题,我使用Cocos2d模板用Xcode 4.3编写了一个演示应用程序,只需修改HelloWorldLayer的init方法,这种现象仍然存在。代码如下: -(void) init {

当我尝试在iTouch 5上构建和运行我的游戏(基于Cocos2d 1.0.1,内置于Xcode 4.5和iOS 6.0 SDK)时,我发现CmenuItems行为不正常:当menuitem与屏幕边缘相邻时,边缘边框似乎不太容易在内部被点击以响应触摸事件(对不起,我的表达不好)

为了演示这个问题,我使用Cocos2d模板用Xcode 4.3编写了一个演示应用程序,只需修改HelloWorldLayer的init方法,这种现象仍然存在。代码如下:

    -(void) init
    {
            // always call "super" init
            // Apple recommends to re-assign "self" with the "super" return value
            if( (self=[super init])) {

            CCLayerColor *cl = [CCLayerColor layerWithColor:ccc4(ccWHITE.r, ccWHITE.g, ccWHITE.b, 255)];
            [self addChild:cl];
                    // create and initialize a Label
                    CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];

                    // ask director the the window size
                    CGSize size = [[CCDirector sharedDirector] winSize];

                    // position the label on the center of the screen
                    label.position =  ccp( size.width /2 , size.height/2 );

                    // add the label as a child to this Layer
                    [self addChild: label];

                    float width = 160;

                    CCSprite *sp1 = [CCSprite node];
                    [sp1 setContentSize:CGSizeMake(width, width)];
                    [sp1 setTextureRect:CGRectMake(0, 0, width, width)];
                    [sp1 setColor:ccc3(0xff, 0xff, 0)];

                    CCSprite *sp2 = [CCSprite node];
                    [sp2 setContentSize:CGSizeMake(width, width)];
                    [sp2 setTextureRect:CGRectMake(0, 0, width, width)];
                    [sp2 setColor:ccc3(0, 0, 0xff)];

                    CCMenuItemSprite *button = [CCMenuItemSprite itemFromNormalSprite:sp1 selectedSprite:sp2 target:nil selector:nil];
                    CCMenu *menu = [CCMenu menuWithItems:button, nil];
                    [self addChild:menu];
                    menu.position = ccp(0, 0);
                    button.anchorPoint = ccp(1, 1);
                    button.position = ccp([[CCDirector sharedDirector] winSize].width,
                                  [[CCDirector sharedDirector] winSize].height);


            }
            return self;
    }
我在互联网上到处找了找,但运气不好,不知道有人能帮我解决这个问题。非常感谢

只是一些预感:

  • 不要设置精灵内容大小。它们应自动设置,并可由CCMenu使用
  • 确保您不会更改项目的位置或锚点。也不要更改CCMenu的主播点。这会干扰触摸检测。仅使用CCMenu的位置属性
  • 确保项目中其他地方没有其他触摸代码干扰和可能吞咽触摸。手势识别器也可能导致CCMenu行为不当

如果要自由定位菜单项,请确保将每个菜单项包装在CCMenu节点中。然后您可以通过菜单定位项目。

这可能是硬件限制/校准错误。您可以制作一个小的“在每个接触点上显示十字线”应用程序进行验证。也可以认为这是硬件限制。您可以检查所有iOS原生的UIKit应用程序,在屏幕边缘附近没有按钮。此外,我发现无论我将菜单项放在屏幕的何处,点击菜单项的左下角都比点击右上角容易,这是我的错觉还是系统真的是这样工作的?