Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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_Sprite Kit_Uitapgesturerecognizer - Fatal编程技术网

Ios 如何扩展触碰以处理连续触碰?

Ios 如何扩展触碰以处理连续触碰?,ios,sprite-kit,uitapgesturerecognizer,Ios,Sprite Kit,Uitapgesturerecognizer,我使用下面的代码在屏幕被“点击”时发射炮弹(在基于精灵套件的游戏中),这一切都很好。然而,我想对此进行扩展,以便在用户“触摸并按住屏幕”的同时重复调用handleTap。有人能为我指出正确的方向吗 // INITIAL SETUP UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [tapRecogni

我使用下面的代码在屏幕被“点击”时发射炮弹(在基于精灵套件的游戏中),这一切都很好。然而,我想对此进行扩展,以便在用户“触摸并按住屏幕”的同时重复调用handleTap。有人能为我指出正确的方向吗

// INITIAL SETUP
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setNumberOfTouchesRequired:1];
[view addGestureRecognizer:tapRecognizer];

改用:

或者使用
触摸开始:withEvent:
触摸结束:withEvent:
方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     // Start shooting
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     // End shooting
}

谢谢你,安德烈,非常感谢。
// INITIAL SETUP
UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
[view addGestureRecognizer:recognizer];
// WHEN TAPPED
- (void)handleTouch:(UILongPressGestureRecognizer *)recognizer {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [self setupAndFireProjectile];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     // Start shooting
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     // End shooting
}