I have two buttons (Button 1 and button 2) and if I press button 1, note1 starts and if i press button 2, note 2 starts.
So what I try to do is: press button one (note1 starts) and SLIDE to button2 and than should note2 start. As in, you slide without lifting your finger over a piano keyboard and all notes from c to h sound.
I did this with UIImageViews
and I did it also with UIButtons
.
If i press the c1pianoview
it sounds a "c". If I press the d1pianoview
it sounds a "d".
But if I slide without lifting my finger from c1pianoview
to d1pianoview
it only sounds a "c". What did I wrong? Can I also do this with UIButtons
?
Touch down works but sliding doesn't work.
Can somebody help me, please? Here my code:
-(void)touchesBeganNSSet *)touches withEventUIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(c1pianoview.frame, location))
{
NSString *path = [[NSBundle mainBundle]
pathForResource: @"c1piano" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
[theAudio play];
}
if(CGRectContainsPoint(d1pianoview.frame, location))
{
NSString *path = [[NSBundle mainBundle]
pathForResource: @"d1piano" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc]
initWithContentsOfURL: [NSURL fileURLWithPathath] error:NULL];
[theAudio play];
}
}
Update:
I have a further question. Now I have two UIImageVIews
on each other. A black piano key over two white piano keys. If I press on the black key it also sound the note from the white key under it.
How do I prevent this?