2012-11-20 37 views
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:方法事件]; }

回答

1

既然你檢測你的「按鈕」使用抽頭點座標觸摸,你應該只需在您的touchesBegan添加邏輯來檢查,如果你的按鈕已經被挖掘出來。例如。向課堂添加一個「BOOL button1Tapped」變量。

相關問題