How to stretch images on touch direction in iPhone sdk?

978 views Asked by At

I am working on customizing images. My requirement is to stretch or shrink image in touch direction & cropping image. I have done cropping but how I can stretch & shrink image in touch direction. Is it possible?

1

There are 1 answers

1
jamil On

Your question in not clear.but if you want to scale or rotate image with touch event.then in viewdidload write this code.

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc]
initWithTarget:self action:@selector(rotateImage:)];
[self.view addGestureRecognizer:rotationGesture];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] 
 initWithTarget:self action:@selector(scaleImage:)];
[self.view addGestureRecognizer:pinchGesture];
 [pinchGesture release];

And using this code you can rotate or scale images in touch direction.

 - (void)scaleImage:(UIPinchGestureRecognizer *)recognizer
{
if([recognizer state] == UIGestureRecognizerStateEnded) {
    previousScale = 1.0;
    return;
}
 CGFloat newScale = 1.0 - (previousScale - [recognizer scale]);
 CGAffineTransform currentTransformation = yourimage.transform;
 CGAffineTransform newTransform = CGAffineTransformScale(currentTransformation,
 newScale, newScale);
    yourimage.transform = newTransform;
    previousScale = [recognizer scale];
 }


- (void)rotateImage:(UIRotationGestureRecognizer *)recognizer
 {

 if([recognizer state] == UIGestureRecognizerStateEnded) {

    previousRotation = 0.0;
    return;
 }

 CGFloat newRotation = 0.0 - (previousRotation - [recognizer rotation]);
 CGAffineTransform currentTransformation = yourimage.transform;
 CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);
 yourimage.transform = newTransform;
 previousRotation = [recognizer rotation];

 }