gpt4 book ai didi

IOS:正确的屏幕触摸次数

转载 作者:可可西里 更新时间:2023-11-01 03:39:22 28 4
gpt4 key购买 nike

在我的应用中,我需要捕捉屏幕上手指的确切数量,我尝试了两种方法,但我遇到了 2 个不同的问题。

第一种方式:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray *allTouches = [touches allObjects];
int count = [allTouches count];
NSLog(@"number of touch:%d", count);
}

如果我同时使用更多手指,这会给我一个不准确的触摸次数。

第二种方式:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
int num = [touches count];
totalTouch = totalTouch+num;
NSLog(@"number of touch:%d", totalTouch);
}

通过这种方式,我使用了一个全局变量 (totalTouch),每次调用 touchbegan 时我都会增加它,并且我有完美的触摸次数。当然,我在触摸端中将此变量设置为“0”

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
totalTouch = 0;
}

我的问题是,我在 touchbegan 中进行控制的第二种方式是:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
int num = [touches count];
totalTouch = totalTouch+num;

if (totalTouch == numberToVerify){
//IT ENTER HERE EVERYTIME INSIDE THIS IF
}
else{
}
}

所以每次它进入 if-conditions 时,我不想要它,我只想在我有最终的触摸次数时才做这个控制......

最佳答案

在你的

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
int num = [touches count];
totalTouch = totalTouch+num;
NSLog(@"number of touch:%d", totalTouch);
}

您可以通过以下方式获取屏幕上的手指数量

  [[event allTouches]count]

这可以从 - (void)touchesBegan: - (void)touchesEnded:- (void)touchesMoved: 访问p>

关于IOS:正确的屏幕触摸次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15885728/

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