views:

26

answers:

1

I'm having a bit of a problem trying to get touchesBegan to respond to multi 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;
}

Im unclear of how to get it setup so that it will respond to multi touch, right now touchesBegan only works with 1 press. I know there something like im assuming a for(UITOuch *t in something) I cant remember how it works exactly.

Any one know how to do it?

Thanks in advanced.

A: 

You'll only get a single touch by default unless you set multipleTouchEnabled = YES. Then your code should work as expected.

Alex
Where would I define this? Im using @interface MainViewController :UIViewController {In my viewDidLoad? or loadView?
AndrewDK
`viewDidLoad` would be fine. If you're using a NIB, you should be able to set this in Interface Builder. Don't override `loadView` unless you're actually creating your views in code.
Alex