如何在iPhone sdk中按触摸方向拉伸图像?

如何在iPhone sdk中按触摸方向拉伸图像?,iphone,objective-c,ios,uigesturerecognizer,uipinchgesturerecognizer,Iphone,Objective C,Ios,Uigesturerecognizer,Uipinchgesturerecognizer,我正在定制图像。我的要求是在触摸方向拉伸或收缩图像&裁剪图像。我已经做了裁剪,但我如何可以拉伸和收缩触摸方向的图像。有可能吗?您的问题不清楚。但如果您想使用触摸事件缩放或旋转图像,请在viewdidload中编写此代码 UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)]; [se

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

您的问题不清楚。但如果您想使用触摸事件缩放或旋转图像,请在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];

 }

您的问题不清楚。但如果您想使用触摸事件缩放或旋转图像,请在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];

 }

请注意,在将这些手势添加到
视图后,您需要
释放
这样的手势
[pinchGesture release]
,以防止内存泄漏。您可以在创建时使用
autorelease
属性作为另一种解决方案。也许你想编辑你的答案来反映这一点。最后,我认为你的答案是正确的,因此我提出了这个问题,但我希望听到@Gagan Misra提出这个问题。请注意,你需要
释放
你这样的手势
[pinchGesture release]
,然后将它们添加到
视图中,以防止内存泄漏。您可以在创建时使用
autorelease
属性作为另一种解决方案。也许你想编辑你的答案来反映这一点。最后,我认为你的答案是正确的,因此我提出了这个问题,但我希望听到提出这个问题的@Gagan Misra。