UIView(内部有 UIImageView)缩放后如何重置锚点?

发布于 2024-11-16 15:16:44 字数 694 浏览 4 评论 0原文

我想对一些包含 UIImageView 的 UIView 进行 catransform3dmakerotation ,这样它们看起来就像在旋转。它可以工作,但是在我缩放 UIView (并因此拉伸其中的图像)后,锚点是错误的(不再位于图形的中心)。

如何重置锚点?我的意思是真的重置它。因为我尝试了这个:

[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);

每次更改加速度计值时(重新缩放后几乎每 0.1 秒更新一次),图像都会旋转但不再居中,它似乎在其原点 (0,0) 上旋转,而不是(0.5,0.5),尽管它应该在 accelerometer: didAccelerate: 方法中更新。但这没有用。这是重新缩放代码:

UIView* buttView = (UIView*) [self.view viewWithTag:101];
UIImageView* butt = (UIImageView*)[self.view viewWithTag:100];
butt.frame= CGRectMake(butt.frame.origin.x, butt.frame.origin.x, newSize, newSize);
buttView.frame = butt.frame;

谢谢!

I want to do catransform3dmakerotation on some UIView that contain UIImageView so that it looks like they are rotating. It works, BUT the anchor point is wrong (no longer at the center of the graphics) after I scaled the UIView (and hence stretched the image in it).

How to reset the anchor point? I mean REALLY reset it. Because I tried this :

[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);

And every time the accelerometer value is changed, which is updating pretty much every 0.1 second after rescaling, the image is rotating but no longer centered anymore, it seems to be rotating on its origin (0,0), instead of (0.5,0.5), altho it should be updated in the accelerometer: didAccelerate: method. But it didn't work. Here is the rescaling code:

UIView* buttView = (UIView*) [self.view viewWithTag:101];
UIImageView* butt = (UIImageView*)[self.view viewWithTag:100];
butt.frame= CGRectMake(butt.frame.origin.x, butt.frame.origin.x, newSize, newSize);
buttView.frame = butt.frame;

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦亿 2024-11-23 15:16:44

在更改 anchorPoint 之前,您需要记住旧框架,并在更改后重置它。像这样:

CGRect oldFrame = [[self.view viewWithTag:100] frame];
[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);
[[self.view viewWithTag:100] setFrame:oldFrame];

Before changing the anchorPoint you need to remember the old frame and after changing reset it. Like this:

CGRect oldFrame = [[self.view viewWithTag:100] frame];
[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);
[[self.view viewWithTag:100] setFrame:oldFrame];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文