Sprite kit SpriteKit,iOS 9。在SKScene中调用方法touchesBegind:withEvent:

Sprite kit SpriteKit,iOS 9。在SKScene中调用方法touchesBegind:withEvent:,sprite-kit,ios9,xcode7,touchesbegan,Sprite Kit,Ios9,Xcode7,Touchesbegan,SKShapeNode是在气泡公司中创建的,气泡可以通过敲击移动。该项目在iOS 8上启动后即可正常运行,触摸操作正在正确进行。在iOS 9上启动时,气泡被创建,物理工作正常(创建时,气泡相互反弹)。但他们不会在点击时做出反应,触摸开始:withEvent:不会被激活。编译器不会生成错误。如果有人曾经遇到过这样的问题,并且已经解决了,或者知道解决方案,请让我知道 这就是我创建气泡的方式: // при создании изначальное положение по горизонтали в

SKShapeNode是在气泡公司中创建的,气泡可以通过敲击移动。该项目在iOS 8上启动后即可正常运行,触摸操作正在正确进行。在iOS 9上启动时,气泡被创建,物理工作正常(创建时,气泡相互反弹)。但他们不会在点击时做出反应,触摸开始:withEvent:不会被激活。编译器不会生成错误。如果有人曾经遇到过这样的问题,并且已经解决了,或者知道解决方案,请让我知道

这就是我创建气泡的方式:

// при создании изначальное положение по горизонтали выбирается рандомно
SKShapeNode *ballPhysics = [[SKShapeNode alloc] init];
CGPathRef ballPhysicsPath = CGPathCreateWithEllipseInRect(CGRectMake( - ballRadius, - ballRadius, ballRadius * 2.f, ballRadius * 2.f), 0);
ballPhysics.path = ballPhysicsPath;
ballPhysics.position = CGPointMake(self.frame.size.width/2.f - 20.f + (arc4random() % 40), 6.f*self.frame.size.height/5.f);
ballPhysics.zPosition = 0;

// ширина линии, цвет и имя шарика
ballPhysics.lineWidth = 3;
ballPhysics.strokeColor = task.color;
ballPhysics.fillColor = [SKColor whiteColor];
ballPhysics.name = task.ballIdentifier;

// физическое тело
CGPathRef ballPhysicsBodyPath = CGPathCreateWithEllipseInRect(CGRectMake( - ballRadius - 2, - ballRadius - 2, ballRadius * 2.f + 4, ballRadius * 2.f + 4), 0);
ballPhysics.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath: ballPhysicsBodyPath];
ballPhysics.physicsBody.dynamic = YES;
ballPhysics.physicsBody.restitution = 0.0f;
ballPhysics.physicsBody.mass = 0.1f;
ballPhysics.physicsBody.friction = 0.0f;
ballPhysics.physicsBody.categoryBitMask = ballCategory;
ballPhysics.physicsBody.collisionBitMask = ballCategory | funnelCategory | edgeCategory;
ballPhysics.physicsBody.contactTestBitMask = ballCategory | funnelCategory | edgeCategory;
ballPhysics.physicsBody.allowsRotation = NO;
ballPhysics.physicsBody.usesPreciseCollisionDetection = YES;

// добавляем объект на сцену
[self addChild:ballPhysics];
方法touchesbeated:withEvent:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInNode:self];
    SKNode *touchedNode = [self nodeAtPoint:touchLocation];

    if ([touchedNode.name hasPrefix:@"ball_"])
    {
        self.touch = touch;
        self.selectedNode = (SKShapeNode *) touchedNode;
        self.selectedNode.physicsBody.mass = 0.3f;
        return;
    }

    // говорим делегату, что было касание между шарами
    if ([self.delegateMovingBalls respondsToSelector:@selector(touchesBetweenBalls)])
        [self.delegateMovingBalls touchesBetweenBalls];
}

发生了什么事?

可能导致此问题的两个主要原因:

  • userInteractionEnabled
    设置为false
  • 您在顶部有一个视图阻止底层内容接收触摸

  • userInteractionEnabled=YES
    ?@Astoria我保留默认值。但是,即使我规定userInteractionEnabled=YES,球仍然没有反应……当你在
    场景中触摸时,
    触摸开始
    是否被激发?你尝试更改了哪个对象的
    userInteractionEnabled
    -属性?球视图还是场景视图?@Astoria抱歉,它确实是userInteractionEnabled=NO的superview之一。奇怪的是,在iOS 8上它没有引起问题。非常感谢你的帮助,你救了我一天)