views:

27

answers:

1

Hello all,

i used the code below to handel the touches in my app and i used for loop in touchesBegan to handel 2 touches in the same time but the problem is if the user make a drag with 2 fingers just one work can i make the 2 works properly ?

code:

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

touchesMoved code :

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    MainViewController *Note = [[MainViewController alloc] init];
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:touch.view];
    NSLog(@"pointx: %f pointy:%f", location.x, location.y);

    if(CGRectContainsPoint(b_do.frame , location)) 
    {
        if (![b_do isHighlighted]){
            [Note playNote:[b_do currentTitle] type:@"wav"];
            [self b_do];
            [b_do setHighlighted:YES];
            NSLog(@"Doooo");
        }
    }else {
        [b_do setHighlighted:NO];
        NSLog(@"Not Do");
    }

    if(CGRectContainsPoint(b_re.frame, location)) 
    {
        if (!b_re.isHighlighted){
            [self b_re];
            [Note playNote:[b_re currentTitle] type:@"wav"];
            [b_re setHighlighted:YES];
        }
    }else {
        [b_re setHighlighted:NO];
    }
    if(CGRectContainsPoint(b_me.frame, location))
    {
        if (!b_me.isHighlighted){
            [self b_me];
            [Note playNote:[b_me currentTitle] type:@"wav"];
            [b_me setHighlighted:YES];
        }
    }else {
        [b_me setHighlighted:NO];
    }
    if (CGRectContainsPoint(b_fa.frame, location)) 
    {
        if (!b_fa.isHighlighted){
            [self b_fa];
            [Note playNote:[b_fa currentTitle] type:@"wav"];
            [b_fa setHighlighted:YES];
        }
    }else {
        [b_fa setHighlighted:NO];
    }
    if (CGRectContainsPoint(b_sol.frame, location)) 
    {
        if (!b_sol.isHighlighted){
            [self b_sol];
            [Note playNote:[b_sol currentTitle] type:@"wav"];
            [b_sol setHighlighted:YES];
        }
    }else {
        [b_sol setHighlighted:NO];
    }
    if (CGRectContainsPoint(b_la.frame, location)) 
    {
        if (!b_la.isHighlighted){
            [self b_la];
            [Note playNote:[b_la currentTitle] type:@"wav"];
            [b_la setHighlighted:YES];
        }
    }else {
        [b_la setHighlighted:NO];
    }
    if (CGRectContainsPoint(b_ci.frame, location))
    {
        if (!b_ci.isHighlighted){
            [self b_la];
            [Note playNote:[b_ci currentTitle] type:@"wav"];
            [b_ci setHighlighted:YES];
        }
    }else {
        [b_ci setHighlighted:NO];
    }
    if (CGRectContainsPoint(b_doo.frame, location)) 
    {
        if (!b_doo.isHighlighted){
            [self b_doo];
            [Note playNote:[b_doo currentTitle] type:@"wav"];
            [b_doo setHighlighted:YES];
        }
    }else {
        [b_doo setHighlighted:NO];
    }
}
+1  A: 

If you are on 3.2 or higher I suggest you change that to use a GestureRecognizer which is a lot easier to use and understand than touchesBegan stuff.

willcodejavaforfood