2 つのボタン (ボタン 1 とボタン 2) があり、ボタン 1 を押すとノート 1 が開始し、ボタン 2 を押すとノート 2 が開始します。
だから私がやろうとしているのは、ボタン1を押して(note1が開始する)、ボタン2にSLIDEすると、note2が開始するはずです。のように、ピアノの鍵盤の上で指を離さずにスライドすると、c から h までのすべての音が鳴ります。
私はこれを でUIImageViews
行い、また で行いましUIButtons
た。
を押すc1pianoview
と「c」と鳴ります。を押すとd1pianoview
「ド」と鳴ります。
しかし、指を離さずにスライドするc1pianoview
とd1pianoview
、「c」としか聞こえません。私は何を間違えたのですか?でこれを行うこともできますUIButtons
か?
タッチダウンはできますが、スライドは機能しません。
誰か助けてくれませんか?ここに私のコード:
-(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];
}
}
アップデート:
さらに質問があります。今、私はUIImageVIews
お互いに2つ持っています。2 つの白いピアノ キーの上に黒いピアノ キー。黒鍵を押すと、その下の白鍵の音も鳴ります。
これを防ぐにはどうすればよいですか?