gpt4 book ai didi

iphone - 触摸计数检测和执行功能

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

tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; tapGesture.numberOfTapsRequired = 2; tapGesture.numberOfTouchesRequired = 1;

[self.view addGestureRecognizer:tapGesture];
[tapGesture release];

- (void)handleTapGesture:(UITapGestureRecognizer *)sender {

if (sender.state == UIGestureRecognizerStateRecognized) {
// handling code
NSLog(@"We got double tap here");
DashBoardViewController* dashboardObj = [[DashBoardViewController alloc] initWithNibName:@"DashBoardViewController" bundle:nil];
[self.navigationController pushViewController:dashboardObj animated:YES];
}

我想做的是,我想在单击和双击时调用 2 个不同的事件。那么我如何检测 tap==1 和 tap==2?在我的代码中可以识别双击,但我不确定在找到单击时如何查找和工作。

谢谢

最佳答案

这可能会给你一个解决方案

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];

[doubleTap setNumberOfTapsRequired:2];
[singleTap setNumberOfTouchesRequired:1];

[self.view addGestureRecognizer:singleTap];
[self.view addGestureRecognizer:doubleTap];

- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap action
}

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
// double tap action
}

或者你必须使用 NSTimer 作为 darren 指向来验证单点触摸。

在方法中,

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

关于iphone - 触摸计数检测和执行功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15425164/

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