views:

137

answers:

1

Hello,

1) I'm doing pinch zoom on the UIImageView , how should i decide upon the zoomfactor value, because when the zoomfactor value goes beyond 0[i.e negative value]the image is gettig tilted, which i dont want it to happen. how to avoid this situation.

2) Y is the flickring kind of rotationis happening, Y not the smooth rotation? ll this be taken care by CGAffineTransformMakeScale(zoomfactor,zoomfactor);method?

This is what i'm doing in my code: zoomFactor = 0;// Initially zoomfactor is set to zero

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@" Inside touchesBegan ..................");

    NSArray *twoTouches = [touches allObjects];
    UITouch *first = [twoTouches objectAtIndex:0];

    OPERATION = [self identifyOperation:touches :first];
    NSLog(@"OPERATION : %d",OPERATION);
    if(OPERATION == OPERATION_PINCH){
        //double touch pinch
        UITouch *second = [twoTouches objectAtIndex:1];
        f_G_initialDistance = distanceBetweenPoints([first locationInView:self.view],[second locationInView:self.view]);
    }
    NSLog(@" leaving touchesBegan ..................");
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@" Inside touchesMoved .................");

    NSArray *twoTouchPoints = [touches allObjects];
    if(OPERATION == OPERATION_PINCH){

        CGFloat currentDistance = distanceBetweenPoints([[twoTouchPoints objectAtIndex:0] locationInView:self.view],[[twoTouchPoints objectAtIndex:1] locationInView:self.view]);
        int pinchOperation = [self identifyPinchOperation:f_G_initialDistance :currentDistance];
        G_zoomFactor = [self calculateZoomFactor:pinchOperation :G_zoomFactor];
        [uiImageView_G_obj setTransform:CGAffineTransformMakeScale(G_zoomFactor, G_zoomFactor)];

        [self.view bringSubviewToFront:resetButton];
        [self.view bringSubviewToFront:uiSlider_G_obj];

        f_G_initialDistance = currentDistance;
    }

    NSLog(@" leaving touchesMoved ..................");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@" Inside touchesEnded ..................");

    NSArray *twoTouches = [touches allObjects];
    UITouch *first = [twoTouches objectAtIndex:0];

    if(OPERATION == OPERATION_PINCH){
        //do nothing
    }
    NSLog(@" Leaving touchesEnded ..................");
}

Thank You.

A: 

If you're able to limit your app to OS 3.2 or above (or if it's an iPad-only app) suggest you take a look at UIPinchGestureRecognizer and UIGestureRecognizer classes. They take away a lot of the pain. You can take the scale or rotation values they return and directly feed them into a CGAffineTransform creation function.

Ramin