如何在我的GameScene.m文件中添加gestureRecognizer?

时间:2015-01-23 00:26:14

标签: ios objective-c sprite-kit uigesturerecognizer

我正在尝试制作游戏,我希望能够检测到滑动角度。我不确定我是否知道如何,但是当我尝试将一个gestureRecognizer添加到GameScene.m文件时,我的代码部分会给我一个错误。

 -(IBAction) someMethod {
     UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
     [panRecognizer setMinimumNumberOfTouches:1];
     [panRecognizer setMaximumNumberOfTouches:1];
     [GameScene addGestureRecognizer:panRecognizer];
     [panRecognizer release]; }

当我添加它时,在第3行,它给我以下错误。:

No known class method for selector 'addGestureRecognizer:'

我是否必须导入一些东西才能使用?谢谢你的帮助!

2 个答案:

答案 0 :(得分:1)

方法addGestureRecognizer是UIView类的成员 - 因此您需要从SKScene视图成员调用它。

所以试试这个......

[[self view] addGestureRecognizer:panRecognizer];

答案 1 :(得分:0)

在你的GameScene.m

- (void)didMoveToView:(SKView *)view {
    UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
    [[self view] addGestureRecognizer:gestureRecognizer];
}