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 af开发者_JAVA百科ter a scaling(shrinking and large) of image. Any one help me plz asap.
Thanks in advanced:)
-(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);
}
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).
精彩评论