我正在尝试制作游戏,我希望能够检测到滑动角度。我不确定我是否知道如何,但是当我尝试将一个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:'
我是否必须导入一些东西才能使用?谢谢你的帮助!
答案 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];
}