我有一些多点触控问题
这是我在 .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/