0

I have one imageview.when i add pinch gesture recognizer,it works fine.but when we do pinchout horizontally, width of Imageview only must be increased.when we do vertically,height only must be increased.how can i do it please?I have coded as following,but when i pinch out vertically,height only must increased.but the view is disappeared.

- (id)initWithFrame:(CGRect)frame {

self = [super initWithFrame:frame];
if (self) {
    // Initialization code.
}

UIPinchGestureRecognizer *panGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[self addGestureRecognizer:panGestureRecognizer];
[panGestureRecognizer release];

return self;


}

   -(void) handlePinch:(UIPinchGestureRecognizer *)gesture 
   {

UIPinchGestureRecognizer *pinchGesture = (UIPinchGestureRecognizer *) gesture;




if ([pinchGesture state] == UIGestureRecognizerStateBegan){

    lastTouchPosition = [pinchGesture locationInView:self];

} else if ([gesture state] == UIGestureRecognizerStateBegan || [pinchGesture state] == UIGestureRecognizerStateChanged){

    CGPoint currentTouchLocation = [pinchGesture locationInView:self];
    CGPoint deltaMove =[self CGPointDistance:currentTouchLocation p2:lastTouchPosition];
    float distance = sqrt(deltaMove.x*deltaMove.x + deltaMove.y*deltaMove.y);
    float hScale = 1 - abs(deltaMove.x)/distance * (1-pinchGesture.scale);
    float vScale = 1 - abs(deltaMove.y)/distance * (1-pinchGesture.scale);
    self.transform = CGAffineTransformScale([self transform], hScale, vScale);

    lastTouchPosition = currentTouchLocation;
}
nameless
  • 809
  • 3
  • 9
  • 27

1 Answers1

1

See this thread. Basically you have to use different values for your affine transforms.

Community
  • 1
  • 1
Viraj
  • 1,880
  • 22
  • 31