2010-06-17 42 views
2

我在嘗試觸碰問題時遇到了一些問題,以響應多點觸控。多點觸控開始

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

NSSet *allTouches = [event allTouches]; 
for (UITouch *touch in allTouches) 
{ 
CGPoint location = [touch locationInView:touch.view]; 
if(CGRectContainsPoint(snare.frame, location) && lastButton != snare) { 
    //Swap Image 
    snareImg.image = snareImgDown; 
    [self performSelector:@selector(swapBack) withObject:nil afterDelay:0.1]; 
    //Play Sound 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"snare" 
                ofType:@"wav"]; 
    SystemSoundID soundID; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path] 
            , &soundID); 
    AudioServicesPlaySystemSound (soundID); 
    // 
    lastButton = snare; 
} 
else if(CGRectContainsPoint(hiHat.frame, location) && lastButton != hiHat) { 
    //Play Sound 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"hi_hat" 
                ofType:@"wav"]; 
    SystemSoundID soundID; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path] 
            , &soundID); 
    AudioServicesPlaySystemSound (soundID); 
    // 
    lastButton = hiHat; 
} 

,我不知道如何得到它的設置,這樣它會以多點觸摸做出反應,現在的touchesBegan只有1點按工作。我知道那裏有我喜歡的東西(UITOuch * t),我不記得它是如何工作的。

任何人都知道該怎麼做?

+1

您是否在視圖中設置了'multipleTouchEnabled = YES'? – 2010-06-17 14:38:38

回答

8

默認情況下,您只會獲得一次觸摸,除非您設置了multipleTouchEnabled = YES。然後你的代碼應該按預期工作。

+0

我在哪裏定義這個? 即時通訊使用 @interface MainViewController:UIViewController { 在我的viewDidLoad?或loadView? – AndrewDK 2010-06-17 15:49:04

+0

'viewDidLoad'會很好。如果您使用的是NIB,則應該可以在Interface Builder中進行設置。除非實際上是在代碼中創建視圖,否則不要重載'loadView'。 – Alex 2010-06-17 16:22:35