gpt4 book ai didi

objective-c - 多点触控touchesBegan

转载 作者:行者123 更新时间:2023-12-04 02:39:49 24 4
gpt4 key购买 nike

我在尝试让 touchesBegan 响应多点触控时遇到了一些问题。

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

NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
{
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(snare.frame, location) && lastButton != snare) {
//Swap Image
snareImg.image = snareImgDown;
[self performSelector:@selector(swapBack) withObject:nil afterDelay:0.1];
//Play Sound
NSString *path = [[NSBundle mainBundle] pathForResource:@"snare"
ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
, &soundID);
AudioServicesPlaySystemSound (soundID);
//
lastButton = snare;
}
else if(CGRectContainsPoint(hiHat.frame, location) && lastButton != hiHat) {
//Play Sound
NSString *path = [[NSBundle mainBundle] pathForResource:@"hi_hat"
ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
, &soundID);
AudioServicesPlaySystemSound (soundID);
//
lastButton = hiHat;
}

我不知道如何设置它以响应多点触控,现在 touchesBegan 仅适用于按下 1 次。我知道有一些东西就像我假设一个 for(UITOuch *t in something) 我不记得它是如何工作的。

有人知道怎么做吗?

最佳答案

除非您设置multipleTouchEnabled = YES,否则默认情况下您只会获得一次触摸。 .那么您的代码应该会按预期工作。

关于objective-c - 多点触控touchesBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3062631/

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