我的问题是当我按住一个按钮时它有声音,此时我触摸我另一根手指的同一个按钮,它也有声音。那么当我已经在同一个按钮上按住手指时,我可以禁用另一个触摸吗?与 TouchesMoved 相同的问题。
int touchesCount;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
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];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
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];
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[img1 setHighlighted:NO];
[img2 setHighlighted:NO];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesEnded:touches withEvent:event]; }