我有两个按钮(按钮1和按钮2),如果我按下按钮1,注1开始,如果我按下按钮2,注意2点开始。幻灯片不抬起手指
所以我尝试做的是:按一个按钮(注1开始),并滑动到BUTTON2比应注2开始。如您所说,您滑动时不会将手指放在钢琴键盘上,并且所有音符都会从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 2010-02-07 12:51:46
@franhu - Dimitris打我吧 – willcodejavaforfood 2010-02-07 13:06:52