水平缩放 UIView
我正在尝试水平缩放视图,但没有得到预期的结果。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刚刚发现问题了。
设置 certer 时,新点必须相对于框架,而不是边界。
所以,我得到了代码:
希望它能帮助别人..
谢谢帮助
Just found the problem.
when setting certer, the new point must be relative to frame, not bounds.
so, i get the code:
Hope it helps somebody..
Thx for help
如果视图框架的原点位于左上角(这是默认设置),则增加视图的宽度只会将其缩放到右侧。
这应该可行:
您不需要调整原点/中心点以仅向右缩放。
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:
You do not need to adjust the origin/center point to scale only to the right.
尝试使用仿射变换:
然后设置中心。
Try using an affine transform instead:
And then setting the center.