gpt4 book ai didi

ios - 变换 View ,保持 subview 大小

转载 作者:行者123 更新时间:2023-11-29 12:44:50 25 4
gpt4 key购买 nike

我有一个 View ,用户可以通过 UIGestureRecognizer缩放旋转。该 View 包含两个 View :

 superview
- content
- button

content 应该缩放和旋转,button 应该保持它的大小和位置。
我在 CGAffineTransformUIGestureRecognizer 的帮助下缩放和旋转 View 。


我怎样才能做到这一点?

我试过:

  • 缩放/旋转 superview 并重置 button 变换和位置。没有成功。
  • 缩放/旋转content 并尝试将content.frame.size 设置为superview。没有成功。 (虽然我认为这必须以某种方式起作用)。
  • 还有一些不为人知的坏事,不值得一提。

编辑:

处理旋转和缩放的代码:

if ([recognizer respondsToSelector:@selector(rotation)]) {
CGFloat rotation = 0.0f - (self.lastRotation - [(UIRotationGestureRecognizer *) recognizer rotation]);

CGAffineTransform currentTransform = self.content.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
self.content.transform = newTransform;

self.lastRotation = [(UIRotationGestureRecognizer *) recognizer rotation];

} else if ([recognizer respondsToSelector:@selector(scale)]) {
CGFloat scale = 1.0f - (self.lastScale - [(UIPinchGestureRecognizer *) recognizer scale]);

CGAffineTransform currentTransform = self.content.transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
self.content.transform = newTransform;

self.lastScale = [(UIPinchGestureRecognizer *) recognizer scale];
}

只是基本的缩放和旋转,没什么特别的。

最佳答案

实际解决方案:

if ([recognizer respondsToSelector:@selector(rotation)]) {
CGFloat rotation = 0.0f - (self.lastRotation - [(UIRotationGestureRecognizer *) recognizer rotation]);

CGAffineTransform currentTransform = self.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
self.transform = newTransform;

self.lastRotation = [(UIRotationGestureRecognizer *) recognizer rotation];

} else if ([recognizer respondsToSelector:@selector(scale)]) {
CGFloat scale = 1.0f - (self.lastScale - [(UIPinchGestureRecognizer *) recognizer scale]);

CGRect bounds = self.bounds;
bounds.size.width *= scale;
bounds.size.height *= scale;
self.bounds = bounds;

self.lastScale = [(UIPinchGestureRecognizer *) recognizer scale];
}

关于ios - 变换 View ,保持 subview 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921934/

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