多点触控开始

时间:2010-06-17 14:36:44

标签: objective-c xcode touch

我在尝试触摸触摸时遇到了一些问题,以响应多点触控。

-(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 in something)我无法记住它是如何工作的。

任何人都知道该怎么做?

1 个答案:

答案 0 :(得分:8)

除非您设置multipleTouchEnabled = YES,否则默认情况下只会进行一次触摸。然后你的代码应该按预期工作。