Search code examples
iphoneiosobjective-cuigesturerecognizeruipinchgesturerecognizer

how to get the coordinate of pinchgesture in iphone


I am working on UIPinchGesture its working fine. I want to find the coordinate of image(x,y,width,height) when shrink and large every time. My code is:

-(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {

CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
CGPoint point = [sender locationInView:self.moveImageView];
NSLog(@"The Coordinate is:--->  x = %f y = %f", point.x, point.y);
if (factor > 1) {

moveImageView.transform = CGAffineTransformMakeScale(lastScaleFactor + (factor-1), lastScaleFactor + (factor-1)); } else { moveImageView.transform = CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor * factor);

                    }

if (sender.state == UIGestureRecognizerStateEnded){
    if (factor > 1) {
        lastScaleFactor += (factor-1);
    } else {
        lastScaleFactor *= factor;

        }       
    }   

}

moveImageView is the object of UIIMageView. The coordinate of x and y are printed, but we need also the height and width.

this work fine, i want to find the current coordinate (x,y,width,height) of image after a scaling(shrinking and large) of image. Any one help me plz asap.

Thanks in advanced:)


Solution

  • If you need the exact state of an UIImageView at any exact state even during an animation, then you need to access the presentation layer. As the model layer is not updated during animation. This can be done like so -

    UIImageView *i    = (UIImageView *)sender;
    CAlayer *imgLayer = [i.layer presentationLayer];
    

    This imgLayer has the exact co-ordinates, you need. including the size (width, height).