水平缩放 UIView

发布于 2025-01-06 12:13:14 字数 356 浏览 4 评论 0原文

我正在尝试水平缩放视图,但没有得到预期的结果。

view.bounds = CGRectMake(view.bounds.origin.x, view.bounds.origin.y , view.bounds.size.width * scaleX, view.bounds.size.height );
view.center = CGPointMake(view.bounds.origin.x, view.center.y);

正如您在上面的代码中看到的,我想将视图缩放到右侧。这就是为什么我改变了视图的中心。

问题是视图仍然向两侧缩放! 我用同样的逻辑垂直缩放另一个 UIView 并得到了我期望的结果。

I'm trying to scale a view Horizontally but i'm not getting the results i expected.

view.bounds = CGRectMake(view.bounds.origin.x, view.bounds.origin.y , view.bounds.size.width * scaleX, view.bounds.size.height );
view.center = CGPointMake(view.bounds.origin.x, view.center.y);

As you can see at the code above, i want to scale the view just to the right side. This is why i changed the center of the view.

The problem is that the view stills scaling to both sides!
I did the same logic to scale another UIView vertically and got the result i expected.

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

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

发布评论

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

评论(3

仙气飘飘 2025-01-13 12:13:14

刚刚发现问题了。

设置 certer 时,新点必须相对于框架,而不是边界。
所以,我得到了代码:

view.center = CGPointMake(-view.frame.origin.x, view.center.y);

希望它能帮助别人..

谢谢帮助

Just found the problem.

when setting certer, the new point must be relative to frame, not bounds.
so, i get the code:

view.center = CGPointMake(-view.frame.origin.x, view.center.y);

Hope it helps somebody..

Thx for help

追我者格杀勿论 2025-01-13 12:13:14

如果视图框架的原点位于左上角(这是默认设置),则增加视图的宽度只会将其缩放到右侧。

这应该可行:

view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width * scaleX, view.frame.size.height);

您不需要调整原点/中心点以仅向右缩放。

If the origin of your view's frame is in the top-left (which is the default), increasing the width of your view should scale it to the right only.

This should work:

view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width * scaleX, view.frame.size.height);

You do not need to adjust the origin/center point to scale only to the right.

世界如花海般美丽 2025-01-13 12:13:14

尝试使用仿射变换:

view.transform = CGAffineTransformMakeScale(scaleX, 1)

然后设置中心。

Try using an affine transform instead:

view.transform = CGAffineTransformMakeScale(scaleX, 1)

And then setting the center.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文