gpt4 book ai didi

ios - 在同一 View 上捕获所有主要手势

转载 作者:行者123 更新时间:2023-11-29 04:40:50 27 4
gpt4 key购买 nike

我需要捕捉所有主要手势。例如,我希望能够跟踪用户何时点击一次,点击两次,用一根手指点击一次,用两根手指点击两次,当他捏合时,当他旋转手指时,当他拖动一根手指时,当他拖动两根手指时。

我知道如何执行所有这些功能,问题是我不想触发两个事件。例如,当用户捏合时,我不知道要触发什么拖动事件。另外,当用户拖动一根手指时,我不希望触发点击功能。

这是我到目前为止所拥有的:

-(void)singleTap:(NSIndexPath *)event
{

}

-(void)doubleTapMethod:(id)event
{
if(enableTap==NO){
enableMove=YES;
return;
}

NSLog(@"double tap with number of fingers = %i",TouchesCount);
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

enableTap=YES;
enableMove=NO;


UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];

TapCount = touch.tapCount;


X=location.x;
Y=location.y;

NSData *data = [ @"SSSSS" dataUsingEncoding:NSUTF8StringEncoding];

[udpSocket sendData:data toHost:IP port:Port withTimeout:-1 tag:1];


switch (TapCount) {
case 1:
[self performSelector:@selector(singleTap:) withObject:nil afterDelay: delay];
break;
case 2:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTap:) object:nil];
[self performSelector:@selector(doubleTapMethod:) withObject:nil afterDelay:delay];
break;
case 3:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doubleTapMethod:) object:nil];
//[self performSelector:@selector(tripleTapMethod) withObject:nil afterDelay:delay];
break;
case 4:
//[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(tripleTapMethod) object:nil];
//[self quadrupleTap];
break;
default:
break;
}

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{


enableTap=NO;

if(enableMove==NO)
return;

NSLog(@"touches moved %i",TapCount);
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];

NSData *data = [ [NSString stringWithFormat:@"%i,%i", ((int)location.x)-X,((int)location.y)-Y] dataUsingEncoding:NSUTF8StringEncoding];

[udpSocket sendData:data toHost:IP port:Port withTimeout:-1 tag:1];


}

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

TouchesCount = touches.count;
return;//here


NSData *data = [ @"EEEEEE" dataUsingEncoding:NSUTF8StringEncoding];
[udpSocket sendData:data toHost:IP port:Port withTimeout:-1 tag:1];

}

我知道我错过了很多实现,但我不想继续努力,直到我确定我处于写入路径上。例如,也许我应该使用 UITapGestureRecognizer 类,然后执行以下操作:

UITapGestureRecognizer * r = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewWasDoubleTapped:)];
[r setNumberOfTapsRequired:2];
[r setNumberOfTouchesRequired:2];
[[self view] addGestureRecognizer:r];

最佳答案

是的!为此,您绝对应该使用手势识别器。对于您在原始帖子中提到的所有内容都有手势识别器。

关于ios - 在同一 View 上捕获所有主要手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10419862/

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