如何在iPhone sdk的触摸方向上拉伸图像?
答
你的问题不清楚,但如果你想缩放或旋转图像触摸event.then在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];
}
请注意,在将视图添加到'view'以避免内存泄漏之后,您需要'释放'像''pinchGesture release''这样的手势。您可以使用创建时的autorelease属性作为另一个解决方案。也许你想**编辑**你的答案来反映这一点。最后,我认为你的回答是正确的,因此我提出了这个问题,但我希望听到@Gagan Misra提出的问题。 – antf