如何适配iPhone 4屏幕分辨率?

发布于 2024-09-04 19:28:41 字数 482 浏览 5 评论 0原文

根据 Apple 的说法,iPhone 4 拥有新的、更好的屏幕分辨率:

3.5 英寸(对角线)宽屏多点触控显示屏
960 x 640 像素分辨率,326 ppi

这个小细节对我们的应用程序影响很大。网络上的大多数演示应用程序都有一个共同点:它们认为屏幕具有 320 x 480 像素的固定尺寸来定位视图。因此,大多数(如果不是全部)开发人员所做的是:他们以这样的方式设计所有内容,可触摸区域的大小(例如)为 50 x 50 像素。只要敲一下就够了。事物已相对于左上角定位,以到达屏幕上的特定位置 - 比如说中心或底部的某个位置。

当我们开发高分辨率应用程序时,它们可能无法在旧设备上运行。如果他们这样做,他们将因任何图像大小为 4 倍而遭受很大损失,必须在内存中缩小它们。

According to Apple, the iPhone 4 has a new and better screen resolution:

3.5-inch (diagonal) widescreen Multi-Touch display
960-by-640-pixel resolution at 326 ppi

This little detail affects our apps in a heavy way. Most of the demo apps on the net have one thing in common: They position views in the believe that the screen has a fixed size of 320 x 480 pixels. So what most (if not all) developers do is: they designed everything in such a way, that a touchable area is (for example) 50 x 50 pixels big. Just enough to tap it. Things have been positioned relative to the upper left, to reach a specific position on screen - let's say the center, or somewhere at the bottom.

When we develop high-resolution apps, they probably won't work on older devices. And if they do, they would suffer a lot from 4-times the size of any image, having to scale them down in memory.

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

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

发布评论

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

评论(8

染年凉城似染瑾 2024-09-11 19:28:41

根据支持高分辨率屏幕在视图中,来自 Apple 文档:

在具有高分辨率屏幕的设备上,imageNamed:
imageWithContentsOfFile:,以及
initWithContentsOfFile:方法
自动寻找版本
带有 @2x 的请求图像
其名称中的修饰符。如果找到一个,
它会加载该图像。如果你这样做
不提供高分辨率版本
给定图像的图像对象
仍然加载标准分辨率
图像(如果存在)并缩放它
绘图期间。

当加载图像时,UIImage 对象会自动设置大小和
将属性缩放到适当的值
基于图像文件的后缀。
对于标准分辨率的图像,
将比例属性设置为 1.0 并
将图像的大小设置为
图像的像素尺寸。对于图像
文件名中带有@2x后缀,
它将scale属性设置为2.0并且
将宽度和高度值减半为
补偿比例因子。这些
减半值正确关联到
您需要的基于点的尺寸
在逻辑坐标空间中使用
渲染图像。

According to Supporting High-Resolution Screens In Views, from the Apple docs:

On devices with high-resolution screens, the imageNamed:,
imageWithContentsOfFile:, and
initWithContentsOfFile: methods
automatically looks for a version of
the requested image with the @2x
modifier in its name. It if finds one,
it loads that image instead. If you do
not provide a high-resolution version
of a given image, the image object
still loads a standard-resolution
image (if one exists) and scales it
during drawing.

When it loads an image, a UIImage object automatically sets the size and
scale properties to appropriate values
based on the suffix of the image file.
For standard resolution images, it
sets the scale property to 1.0 and
sets the size of the image to the
image’s pixel dimensions. For images
with the @2x suffix in the filename,
it sets the scale property to 2.0 and
halves the width and height values to
compensate for the scale factor. These
halved values correlate correctly to
the point-based dimensions you need to
use in the logical coordinate space to
render the image.

极致的悲 2024-09-11 19:28:41

这纯粹是猜测,但如果分辨率确实是 960 x 640 - 这恰好是当前版本分辨率的两倍。对于 iPhone 来说,检查应用程序构建目标并检测应用程序的旧版本并简单地将其缩放 2 是非常简单的。您永远不会注意到其中的差异。

This is purely speculation, but if the resolution really is 960 x 640 - that's exactly twice as high a resolution as the current version. It would be trivially simple for the iPhone to check the apps build target and detect a legacy version of the app and simply scale it by 2. You'd never notice the difference.

风吹过旳痕迹 2024-09-11 19:28:41

Engadget 对主题演讲的报道包括以下来自史蒂夫·乔布斯的文字记录

...它使您的应用程序能够运行
自动对此进行处理,但它会呈现
您的文本和控件位于较高的位置
解决。您的应用程序看起来均匀
更好,但如果你做一点
工作,那么它们就会看起来很漂亮。所以
我们建议您这样做

因此我推断,如果您使用现有的 API,您的应用程序将会得到扩展。如果您利用新的 iOS4 API,您就可以通过新像素获得所有乐趣。

Engadget's reporting of the keynote included the following transcript from Steve Jobs

...It makes it so your apps run
automatically on this, but it renders
your text and controls in the higher
resolution. Your apps look even
better, but if you do a little bit of
work, then they will look stunning. So
we suggest that you do that

So I infer from that, if you use existing APIs your app will get scaled up. If you take advantage of new iOS4 APIs, you can get all groovy with the new pixels.

So尛奶瓶 2024-09-11 19:28:41

听起来显示效果没问题,但我担心游戏中的逻辑。 TouchBegan 位置会返回新分辨率中的点吗?屏幕边界会有所不同,这些类型的事情可能对我来说可能是个问题。

It sounds like the display will be ok but I'm concerned about the logic in my game. Will touchesBegan positions return points in the new resolution? The screen bounds will be different, these types of things could potentially be problems for me.

妄断弥空 2024-09-11 19:28:41

出于显示目的缩放到双分辨率很简单,但是这种缩放是否适用于输入/输出屏幕坐标的所有 api?如果不是的话,事情就会破裂,不是吗?

如果它在整个框架中得到广泛处理,那就足够公平了。我想有很多潜在的 api 的这种效果。

Scaling to a double resolution for display purpose is straight forward, but will this scalling apply to all api's that input/output a screen coordinate? If not things are going to break aren't they?

Fair enough if it's been handled extensively throughout the framework.. I would imagine there are a lot of potential api's this effects.

噩梦成真你也成魔 2024-09-11 19:28:41

对于来到此主题寻找移动 Web 界面解决方案的人,请查看 Webkit 博客上的这篇文章:http://webkit.org/blog/55/high-dpi-web-sites/

看来Webkit在四年前就已经解决了这个问题。

For people who are coming to this thread looking for a solution to a mobile web interface, check out this post on the Webkit blog: http://webkit.org/blog/55/high-dpi-web-sites/

It seems that Webkit has solved this problem four years ago.

梦晓ヶ微光ヅ倾城 2024-09-11 19:28:41

是的,这是真的。

根据 WWDC 的说法,苹果似乎已经构建了某种形式的自动转换,以便应用程序的分辨率不会完全关闭。考虑将 DVD 向上转换为 HDTV。

我的猜测是,苹果知道大多数标准开发人员一直在使用什么,并且已经使用它们进行立即转换。当然,如果您正在编写一个应用程序来利用新的分辨率,它看起来会比苹果自动转换的结果好得多。

Yes it is true.

According to WWDC it appears that apple has build it some form of automatic conversion so that the resolution for applications will not be completely off. Think up-convert for dvd to HDTV's.

My guess would be that apple knows what most of the standards developers have been using and will already be using these for an immediate conversion. Of course if you are programming an application to take advantage of the new resolution it will look much nicer than whatever the result of apples auto-conversion is.

一城柳絮吹成雪 2024-09-11 19:28:41

您的所有标签和系统按钮都将采用 326dpi,但您的图像仍将像素加倍,直到您添加高分辨率资源。我目前正在更新我的应用程序。如果您在 iPhone 4 sim 上构建并运行,则显示为 50%,请转到“窗口”>“规模> 100%看到真正的区别!标签很光滑,我的图像看起来令人震惊!

All of your labels and system buttons will be at 326dpi but your images will still be pixel doubled until you add the hi-res resources. I am currently updating my apps. If you build and run on the iPhone 4 sim then it is presented at 50%, go to Window > Scale > 100% to see the real difference! Labels are smooth, my images look shocking!

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