UITapGestureRecognizer在SKView中不起作用

时间:2014-09-03 10:12:35

标签: sprite-kit uigesturerecognizer

我在视图控制器中有这个代码运行场景:

SKView * _skView;
ClassicGameScene* _scene;


- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    if (!_skView) {
        _skView = [[SKView alloc] initWithFrame:self.view.bounds];
        ClassicGameScene *scene =[[ClassicGameScene alloc] initWithSize:_skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;

        [_skView presentScene:scene];
        [self.view addSubview:_skView];
        [self.view setUserInteractionEnabled:YES];
        _scene = scene;
    };
}

在我的场景中我有这个:

- (id)initWithSize:(CGSize)size
{
    if (self = [super initWithSize:size]) {
        [self createSceneContents];
    }
    return self;
}

-(void) createSceneContents
{
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.view setUserInteractionEnabled:YES];
    [self.view addGestureRecognizer:singleTap];

    [self addBackground];
    [self addLabels];
    [self preparePlocha];
}

但是当我点击场景时,我的手势识别器不会 工作(点击程序不会被解雇 - 通过断点测试)。有谁可以帮助我吗? 谢谢。

0 个答案:

没有答案