- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *aTouch in touches) {
if (aTouch.tapCount >= 2) {
// The view responds to the tap
}
}
}
我正在使用上面的代码来检测双击手势;但是,如何才能将代码设置为仅发生一次?
换句话说,当您点按一次时,该字符会跳转。当你快速连续点击两次时,角色会双跳。但是如何设置水龙头的方式是角色不会连续双跳并从单视图中走高而不是最初录制?
答案 0 :(得分:1)
实现这一目标的一种非常简单的方法是通过声明全局bool
变量并在检测到双击后设置其值!
这样的事情:
@interface MyViewController()
{
bool isTapped;
}
@end
@implementation MyViewController
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *aTouch in touches) {
if (aTouch.tapCount >= 2) {
if(!isTapped) {
// The view responds to the tap
isTapped = YES;
}
}
}
}
@end
希望这有帮助
答案 1 :(得分:0)
不确定这是否有帮助,也只是拿一个标志并相应地设置为是或否: -
UILongPressGestureRecognizer *tapRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.delegate = self;
tapRecognizer.minimumPressDuration = //Up to you;
[self.someView addGestureRecognizer:tapRecognizer];