如何延长水龙头来处理连续接触?

时间:2014-01-16 09:40:00

标签: ios sprite-kit uitapgesturerecognizer

当屏幕被“点击”时,我正在使用下面的代码来发射射弹(在基于Sprite Kit的游戏中),这一切都正常。但是我想扩展它,以便在用户“触摸并按住屏幕”时反复调用handleTap“任何人都能指出我正确的方向吗?

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

// WHEN TAPPED
- (void)handleTap:(UITapGestureRecognizer *)recognizer {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [self setupAndFireProjectile];
}

1 个答案:

答案 0 :(得分:1)

改为使用UILongPressGestureRecognizer

// 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];
}

或使用UIResponder's touchesBegan:withEvent:touchesEnded:withEvent:方法:

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

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