1

我正在定制图像。我的要求是在触摸方向和裁剪图像上拉伸或缩小图像。我已经完成了裁剪,但是我如何在触摸方向上拉伸和收缩图像。可能吗?

4

1 回答 1

6

您的问题不清楚。但是如果您想使用触摸事件缩放或旋转图像。那么在 viewdidload 中编写此代码。

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];

使用此代码,您可以在触摸方向上旋转或缩放图像。

 - (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];

 }
于 2012-05-26T08:12:50.427 回答