gpt4 book ai didi

objective-c - 如何缩放和平滑旋转?

转载 作者:行者123 更新时间:2023-12-01 18:30:24 26 4
gpt4 key购买 nike

我看过一些应用程序,它们能够同时缩放和旋转图像。不需要释放手指触摸。

我的以下代码要求:
1.轻触即可缩放
2.释放
3.触摸以旋转

如何同时缩放和旋转?

在我的主要代码中:

UIPanGestureRecognizer *imagePanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)];
[imagePanGesture setMinimumNumberOfTouches:1];
[imagePanGesture setMaximumNumberOfTouches:1];
[tempImageView addGestureRecognizer:imagePanGesture];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleImage:)];
[tempImageView addGestureRecognizer:pinchGesture];

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];
[tempImageView addGestureRecognizer:rotationGesture];

以个人比例旋转
- (void)scaleImage:(UIPinchGestureRecognizer *)recognizer 
{
if([recognizer state] == UIGestureRecognizerStateEnded)
{
previousScale = 1.0;
return;
}

CGFloat newScale = 1.0 - (previousScale - [recognizer scale]);

CGAffineTransform currentTransformation = [recognizer view].transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransformation, newScale, newScale);

[[recognizer view] setTransform: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 = [recognizer view].transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);

[[recognizer view] setTransform:newTransform];

previousRotation = [recognizer rotation];
}

最佳答案

关于objective-c - 如何缩放和平滑旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9576817/

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