缩放 UIView 及其所有子项 [英] Scale UIView and all its children

查看:21
本文介绍了缩放 UIView 及其所有子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有大约 50 个 UIButton 的 UIView.所有按钮位置都以像素为单位,相对于我的主 UIView 的左上角.

I have an UIView with around 50 UIButtons. All button positions were given in pixels, relative to the left upper corner of my main UIView.

视图中使用的所有(背景)图像都具有更高的分辨率.当我将我的应用从 iPhone 移植到 iPad 时,我想增加 UIView 的有效像素大小.

All (background) images used in the view are available in higher resolution. As I am porting my app from iPhone to iPad, I would like to increase the effective pixel size of the UIView.

现在我正在寻找一种将整个 UIView 放大 2* 倍的方法.在不破坏内部元素的位置的情况下,这可能吗?

Now I'm searching a way to upscale the whole UIView by a factor of 2*. Is that possible without destroying the position of the inner elements?

仅供参考,UIView 是在 XCode 的 NIB 文件中设计的.但我不介意它是否可以通过编程来完成.

FYI, the UIView is designed in a NIB-file in XCode. But I don't mind if it can be done programmatically.

推荐答案

我最终使用了

self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);

它允许我保留在 Interface Builder 中创建的设计.

It allowed me to keep the design created in the Interface Builder.

不幸的是,在这种情况下图像的清晰度会受到影响,但与以编程方式编写整个设计的脚本相比,这是一个很小的代价.

Unfortunately the sharpness of the image suffers in that case, but this is a small price to pay compared to scripting the whole design programmatically.

这篇关于缩放 UIView 及其所有子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆