0
我的問題是當我按住一個按鈕它有一個聲音在這個時候我觸摸我的另一個手指的同一個按鈕,它也有一個聲音。所以當我已經按住同一個按鈕時,我可以禁用另一次觸摸嗎?正如同TouchesMoved一樣的問題。touchesbegan和touchesmoved
int touchesCount;
- (無效)的touchesBegan:(NSSet中*)觸摸withEvent:方法(的UIEvent *)事件{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if(CGRectContainsPoint(img1.frame,touchLocation)){
if (!img1.isHighlighted && touchesCount < 1){
[img1 setHighlighted:YES];
[img2 setHighlighted:NO];
NSLog(@" Image 1");
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"c", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}else {
[img1 setHighlighted:NO];
}if (CGRectContainsPoint(img2.frame,touchLocation)){
if (!img2.isHighlighted && touchesCount < 1){
[img2 setHighlighted:YES];
[img1 setHighlighted:NO];
NSLog(@" Image 2");
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"d", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}else {
[img2 setHighlighted:NO];
}
}
- (無效)touchesMoved:(NSSet中*)觸摸withEvent:方法(的UIEvent *)事件{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if(CGRectContainsPoint(img1.frame,touchLocation)){
if (!img1.isHighlighted && touchesCount < 1){
[img1 setHighlighted:YES];
[img2 setHighlighted:NO];
NSLog(@" Image 1");
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"c", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}else {
[img1 setHighlighted:NO];
}if (CGRectContainsPoint(img2.frame,touchLocation)){
if (!img2.isHighlighted && touchesCount < 1){
[img2 setHighlighted:YES];
[img1 setHighlighted:NO];
NSLog(@" Image 2");
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"d", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}else {
[img2 setHighlighted:NO];
}
}
- (無效)touchesEnded:(NSSet中*)觸摸withEvent:方法(的UIEvent *)事件{
[img1 setHighlighted:NO];
[img2 setHighlighted:NO];
}
- (無效)touchesCancelled:(NSSet中*)觸摸withEvent:方法(的UIEvent *)事件{ [自touchesEnded:觸摸withEvent:方法事件]; }