두 개의 버튼 (버튼 1과 버튼 2)이 있으며 버튼 1을 누르면 노트 1이 시작되고 버튼 2를 누르면 노트 2가 시작됩니다.손가락을 짚지 않고 하나의 버튼에서 다른 것으로 슬라이드
그래서 무엇을하려고합니까 : 버튼 1 (note1이 시작)을 누르고 슬라이드 2는 button2로 이동해야하며 note2가 시작되어야합니다. 마찬가지로, 피아노 건반 위로 손가락을 올리거나 c에서 h까지 모든 음표를 들으면서 움직입니다.
나는 이것을 UIImageViews
와 함께했고, 나는 UIButtons
도 사용했다.
c1pianoview
을 누르면 "c"로 들립니다. d1pianoview
을 누르면 "d"소리가납니다.
그러나 손가락을 누르지 않고 슬라이드하면 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
을 서로 가지고 있습니다. 두 개의 흰색 피아노 키를 통해 검은 피아노 키. 검정색 키를 누르면 흰색 키의 음을 들려줍니다.
어떻게 방지합니까?
괜찮아요. touchesMoved와 함께했습니다.하지만 지금은 ImageView에서 슬라이드 할 때마다 음이 들립니다. 하지만 한 번만 음표가 들리길 바래. 내가 뭘 잘못 했니? 도움을위한 thx! – user268086
@franhu - Dimitris가 나를 이길 때 – willcodejavaforfood