1

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:)

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
pinku
  • 87
  • 1
  • 7

2 Answers2

1

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

NSLog(@"image.frame.sizeWidth111 %f",moveImageView.frame.size.width);
NSLog(@"image.frame.sizeHeight111 %f",moveImageView.frame.size.height);

CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
CGPoint point = [sender locationInView:self.moveImageView];

NSLog(@"The Coordinate is:--->  x = %f y = %f", point.x, point.y);

//if the current factor is greater 1 --> zoom in

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;

        }       
    }   
NSLog(@"image.frame.sizeWidth222 %f",moveImageView.frame.size.width);
NSLog(@"image.frame.sizeHeight222 %f",moveImageView.frame.size.height);

}

avinash
  • 611
  • 1
  • 7
  • 22
0

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).

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • thanks for replying me: but please tell me where i put this code. – pinku Aug 08 '11 at 12:27
  • @pinku, you put this code in your pinch method. i.e. as the pinch is happening, if you want the exact this is how... – Srikar Appalaraju Aug 08 '11 at 12:33
  • m putting this on pinch method; moveImageView = (UIImageView )sender; CAlayer *imgLayer = [moveImageView.layer presentationLayer]; – pinku Aug 08 '11 at 12:38
  • i have post our pinch method. please help me. – pinku Aug 08 '11 at 12:41
  • it becomes crash like.. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPinchGestureRecognizer layer]: unrecognized selector sent to instance 0x4b27de0' – pinku Aug 08 '11 at 13:01
  • you need to include `core animation` framework. Without that these delegates are meaning less... – Srikar Appalaraju Aug 08 '11 at 13:24
  • you need to add CORE ANIMATION!!!!! how much simpler do you want me to explain. You question framing too is very confusing & then all these... Try it out earnestly first... – Srikar Appalaraju Aug 08 '11 at 13:36