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