views:

15

answers:

0

Hello, i want to receive the changed distance of two touches in my program after "pinching". First, i start with the touchesBegan:

- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint {
float x = toPoint.x - fromPoint.x;
float y = toPoint.y - fromPoint.y;

return sqrt(x * x + y * y);

}

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count]) {
        case 1: {

        } break;
        case 2: {
            //get out two fingers
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

            //and calculate our initial distance between them
            initialDistance = [self distanceBetweenTwoPoints:[touch1 locationInView: [mainTableViewController_HD Inhalt0]]
                                                     toPoint:[touch2 locationInView:[mainTableViewController_HD Inhalt0]]];
        } break;
    }
}

The MainTableViewController_HD Inhalt0 is the UIView where the two touches start.

Now the user has to "pinch" the both fingers like he want to zoom.

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

NSSet *allTouches = [event allTouches];

switch ([allTouches count])
{
    case 1: { //Move

    } break;
    case 2: { //Zoom
        UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
        UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

        //Calculate the distance between the two fingers.
        CGFloat finalDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:self] 
                                                       toPoint:[touch2 locationInView:self]];

        movedZ = initialDistance - finalDistance;
        initialDistance = finalDistance;
    NSLog(@"distance:%d", movedZ);  
    } break;
}

}

Now, i've got two big problems. First, this all just works if i touch the screen with both fingers at the same time, and second, the variable movedZ just refresh once after pinching, but i want to refresh movedZ after every movement, after every pixel :p Has anyone got an idea? Where is my problem?

Thank you very much for help!