2010-06-17 80 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