gpt4 book ai didi

ios - 如何扩展 tap 以处理连续触摸?

转载 作者:行者123 更新时间:2023-11-29 12:55:49 25 4
gpt4 key购买 nike

当屏幕被“点击”时,我正在使用下面的代码发射弹丸(在基于 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];
}

最佳答案

使用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
}

关于ios - 如何扩展 tap 以处理连续触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21158154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com