【发布时间】:2010-02-07 09:57:11
【问题描述】:
我有两个按钮(按钮 1 和按钮 2),如果我按下按钮 1,note1 启动,如果我按下按钮 2,note 2 启动。
所以我尝试做的是:按下按钮 1(note1 启动)并滑动到按钮 2,然后 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。两个白色钢琴键上的黑色钢琴键。如果我按下黑键,它也会从它下面的白键发出音符。
如何防止这种情况发生?
【问题讨论】:
标签: iphone touchesmoved sliding