我有一些多点触控问题
这是我在 .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”,但是当两根手指按下时,它不会播放任何音乐。