gpt4 book ai didi

iphone - 如何在 iPhone sdk 的触摸方向上拉伸(stretch)图像?

转载 作者:行者123 更新时间:2023-12-01 17:44:13 26 4
gpt4 key购买 nike

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

最佳答案

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

}

关于iphone - 如何在 iPhone sdk 的触摸方向上拉伸(stretch)图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10764480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com