如何适应iPhone 4的屏幕分辨率?

时间:2022-03-20 01:38:34

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

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

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

3.5英寸(对角线)宽屏多点触控显示屏,分辨率为960×640像素,分辨率为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.

这个小细节会严重影响我们的应用程序。网上的大多数演示应用程序都有一个共同点:他们认为屏幕的固定大小为320 x 480像素。因此,大多数(如果不是全部)开发人员所做的是:他们以这样的方式设计所有东西,可触摸区域(例如)50 x 50像素大。足以点击它。事情已经相对于左上角定位,以达到屏幕上的特定位置 - 让我们说中心,或者在底部的某个位置。

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.

当我们开发高分辨率应用程序时,它们可能无法在旧设备上运行。如果他们这样做,他们将遭受4倍于任何图像大小的痛苦,不得不在内存中缩小它们。

8 个解决方案

#1


15  

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

根据支持高分辨率屏幕的观点,来自Apple文档:

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.

在具有高分辨率屏幕的设备上,imageNamed:,imageWithContentsOfFile:和initWithContentsOfFile:方法会自动查找所请求图像的版本,其名称中包含@ 2x修饰符。如果找到一个,它会加载该图像。如果您未提供给定图像的高分辨率版本,则图像对象仍会加载标准分辨率图像(如果存在)并在绘图期间对其进行缩放。

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.

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

#2


6  

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.

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

#3


5  

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

Engadget对主题演讲的报道包括史蒂夫乔布斯的以下成绩单

...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.

因此,我推断,如果您使用现有的API,您的应用程序将扩大规模。如果您利用新的iOS4 API,您可以使用新像素获得所有groovy。

#4


4  

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.

听起来好像显示器还可以,但我很担心游戏中的逻辑。将触及新决议中的开始位置返回点吗?屏幕界限会有所不同,这些类型的东西可能对我来说可能是个问题。

#5


3  

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?

为了显示目的而缩放到双倍分辨率是直截了当的,但这个scalling是否适用于输入/输出屏幕坐标的所有api?如果不是事情会破裂不是吗?

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

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

#6


3  

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/

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

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

似乎Webkit四年前已经解决了这个问题。

#7


2  

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.

根据WWDC的说法,似乎苹果已经建立了某种形式的自动转换,因此应用程序的分辨率不会完全消失。想想转换为DVD到HDTV的。

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.

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

#8


2  

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!

您的所有标签和系统按钮都将为326dpi,但在添加高分辨率资源之前,您的图像仍然会像素加倍。我目前正在更新我的应用。如果您在iPhone 4 SIM上构建并运行,那么它将以50%显示,转到Window> Scale> 100%以查看真正的差异!标签很流畅,我的图像看起来很震撼!

#1


15  

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

根据支持高分辨率屏幕的观点,来自Apple文档:

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.

在具有高分辨率屏幕的设备上,imageNamed:,imageWithContentsOfFile:和initWithContentsOfFile:方法会自动查找所请求图像的版本,其名称中包含@ 2x修饰符。如果找到一个,它会加载该图像。如果您未提供给定图像的高分辨率版本,则图像对象仍会加载标准分辨率图像(如果存在)并在绘图期间对其进行缩放。

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.

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

#2


6  

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.

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

#3


5  

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

Engadget对主题演讲的报道包括史蒂夫乔布斯的以下成绩单

...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.

因此,我推断,如果您使用现有的API,您的应用程序将扩大规模。如果您利用新的iOS4 API,您可以使用新像素获得所有groovy。

#4


4  

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.

听起来好像显示器还可以,但我很担心游戏中的逻辑。将触及新决议中的开始位置返回点吗?屏幕界限会有所不同,这些类型的东西可能对我来说可能是个问题。

#5


3  

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?

为了显示目的而缩放到双倍分辨率是直截了当的,但这个scalling是否适用于输入/输出屏幕坐标的所有api?如果不是事情会破裂不是吗?

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

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

#6


3  

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/

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

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

似乎Webkit四年前已经解决了这个问题。

#7


2  

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.

根据WWDC的说法,似乎苹果已经建立了某种形式的自动转换,因此应用程序的分辨率不会完全消失。想想转换为DVD到HDTV的。

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.

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

#8


2  

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!

您的所有标签和系统按钮都将为326dpi,但在添加高分辨率资源之前,您的图像仍然会像素加倍。我目前正在更新我的应用。如果您在iPhone 4 SIM上构建并运行,那么它将以50%显示,转到Window> Scale> 100%以查看真正的差异!标签很流畅,我的图像看起来很震撼!