ios - 多点触控和音频

标签 ios multi-touch

我有一些多点触控问题

这是我在 .m 文件中的代码的一部分

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint pt = [touch locationInView:self.view];

if(pt.x>634 && pt.x<733 && pt.y >64 && pt.y<145)
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"si" ofType:@"mp3"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio play];
}

if(pt.x>634 && pt.x<733 && pt.y >195 && pt.y<276)
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"la" ofType:@"mp3"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio play];
}


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

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"rest" ofType:@"mp3"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio play];
}

我希望这能奏效。

实际上,第二个“if ((range) &&(range)) ”部分不起作用。谁能告诉我解决办法吗?

第一个范围有效,我希望第二个范围播放“la.mp3”,但是当两根手指接触时,它不会播放任何音乐。

最佳答案

抱歉,这将是对答案的完整编辑,因为我无法删除最后一个答案。我犯了一个重大的阅读错误,我需要写一个新的答案。您不得使用[touches anyObject],因为这无法可靠地为您提供多点触控系统中所需的触摸。

您必须使用[[touches allObjects] objectAtIndex:#] 来提取触摸。触摸将按照它们出现的顺序出现。

关于ios - 多点触控和音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10492337/

相关文章:

ios - 如何在 iOS 12.0 的 UserDefaults 中保存对象数组。使用任何数组 [[String : Any]]

android - 查询多点触控具体支持的指针数

css - 在允许平移 [TOUCHSCREEN] 的同时禁用捏合以放大 IE10

ios - SWIFT 和 EventKit

ios - NSNotFound 不适用于 NSUser 默认值

ios - 按下导航后退按钮时 SWRevealViewController 关闭左侧 View

android - MySQL 到 Sqlite 从 PHP 同步到移动应用程序 (iOS/Android)

安卓多点触控!破解任何人?

c++ - (如何)我可以在 Windows 上模拟触摸事件吗?

qt - 创建多点触控 Qt 5.1 应用程序