xcode 为 Iphone 6 设计的调整大小应用程序以在 iphone 5s 中正确缩放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28044592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:30:58  来源:igfitidea点击:

Resize app designed for Iphone 6 to scale correctly in iphone 5s

iosobjective-cxcodeswiftsize-classes

提问by Tobias

Ok, here is the problem I have designed an application for iphone 6 screen without size classes and autolayout. Looking like below in the storyboard. As you can see its simulated size is 4.7 inch. enter image description here

好的,这是我为 iphone 6 屏幕设计的应用程序的问题,没有大小类和自动布局。在故事板中看起来像下面。如您所见,其模拟尺寸为 4.7 英寸。 在此处输入图片说明

It works perfectly when running on iphone 6 devices obviusly. However when trying to run the app in other devices than iphone 6 it wont scale proportional.

它显然在 iphone 6 设备上运行时完美运行。但是,当尝试在 iphone 6 以外的其他设备上运行该应用程序时,它不会按比例缩放。

My hope was that if I removed the lanuch screen images only keeping the iphone 6 size it would scale to fit other screens looking the same as if it where run on a iphone 6 only scaled up or down depenging on device.

我的希望是,如果我删除了仅保留 iphone 6 尺寸的 lanuch 屏幕图像,它会缩放以适应其他看起来相同的屏幕,就像它在 iphone 6 上运行时仅根据设备放大或缩小一样。

My launch screen looks like this now

我的启动屏幕现在看起来像这样

enter image description here

在此处输入图片说明

It does infact scale the app but it scales the app in wrong proportion making it looked chopped like this.

它确实可以缩放应用程序,但它以错误的比例缩放应用程序,使其看起来像这样被切碎。

Iphone 5s version of the app looks like this enter image description hereAs you can see it scales correctly but the aspect gets wrong compared to the iphone 6 version below scaling correctly. enter image description here

该应用程序的 Iphone 5s 版本如下所示 在此处输入图片说明正如您所看到的,它可以正确缩放,但与下面的 iphone 6 版本相比,它的方面错误了。 在此处输入图片说明

Here is an ipad version looking like the iphone 5s version scaling wrong. enter image description here

这是一个 ipad 版本,看起来像 iphone 5s 版本缩放错误。 在此处输入图片说明

It seems to me that the scaling works since I have removed all launch images except the 4.7 display (iphone 6) The problem however seems to be that it scales keeping the aspect of an iphone 5 in width making the iphone 6 display to wide.

在我看来,缩放是有效的,因为我已经删除了除 4.7 显示器(iphone 6)之外的所有启动图像 然而问题似乎是它缩放保持 iphone 5 的宽度,使 iphone 6 显示为宽。

I have tried to add launch images for all devices but the problem then is that I need to use autolayout and size classes to make it work.

我试图为所有设备添加启动图像,但问题是我需要使用自动布局和大小类来使其工作。

Is there any way to for instance tell the scaling to keep aspect but use iphone 6 width and height intact without using size classes etc.

例如,有什么方法可以告诉缩放保持纵横比,但完整地使用 iphone 6 的宽度和高度而不使用尺寸类等。

To make the question even more simple. Is there any way to scale an app made for strictly iphone 6 so resize to iphone 5s/ipad?

为了使问题更简单。有什么方法可以缩放严格为 iphone 6 制作的应用程序,以便调整为 iphone 5s/ipad?

Any help is highly appreciated!

任何帮助表示高度赞赏!

回答by Daniel Rinser

Well, the "trick" with removing the other launch images doesn't work, as you noticed yourself.. This automatic scaling only works from 4" to 4.7" and 5.5" and is only to support older apps on the new devices, not for general purpose "I am too lazy to support all sizes" use cases.. ;-) Apart from that, you should definitely support the native resolutions.

好吧,删除其他启动图像的“技巧”不起作用,正如您自己注意到的那样。这种自动缩放仅适用于 4" 到 4.7" 和 5.5",并且仅支持新设备上的旧应用程序,而不是对于通用“我懒得支持所有尺寸”用例.. ;-) 除此之外,您绝对应该支持本机分辨率。

So, to answer your question: You can either just use Auto Layout. This is definitely the preferred approach - after all that's exactly the use case that it has been built for.

所以,回答你的问题:你可以只使用自动布局。这绝对是首选方法 - 毕竟这正是它构建的用例。

Alternatively, if you really don't want to or can't use Auto Layout, you either need to make sure to set your auto resizing masks correctly (e.g. "flexible width" on the stuff that needs to grow/shrink horizontally etc.), or adapt your frames manually in code (which partially defeats the purpose of IB).

或者,如果您真的不想或不能使用自动布局,您要么需要确保正确设置自动调整大小的蒙版(例如,需要水平增长/收缩的内容上的“灵活宽度”等) ,或在代码中手动调整您的框架(这部分违背了 IB 的目的)。

回答by Juan Carlos Ospina Gonzalez

If you didn't use Auto-Layout or Size Classes, your only hope is to programmatically change the positions/size of each element individually in the viewDidAppearor viewDidLayoutSubviewsmethod of your LoginViewController. You would have to do it also on orientation change (if your app supports it).

如果您没有使用自动布局或大小类,你唯一的希望就是以编程方式更改每个元素的位置/大小分别在viewDidAppearviewDidLayoutSubviews你的方法LoginViewController。您还必须在方向更改时执行此操作(如果您的应用支持)。

It's a lot of work that can be easily be avoided by using Auto-Layout/Size Classes!

使用自动布局/大小类可以轻松避免很多工作!