扩展iPhone 5的应用程序 - 最佳实践

时间:2023-01-22 20:17:00

Now that Apple is about to start shipping iPhone 5's, I'm looking into extending my applications so they appear full screen on the iPhone 5. I ran my apps on the simulator, and even the ones with a UITableView extending to the bottom of the screen, the black bars appear at the top and bottom of the screen.

既然Apple即将开始发售iPhone 5,我正在考虑扩展我的应用程序,以便它们在iPhone 5上全屏显示。我在模拟器上运行我的应用程序,甚至那些带有UITableView的应用程序延伸到底部屏幕,黑色条显示在屏幕的顶部和底部。

Here's my question: What is the best practice for extending apps for the iPhone 5?

这是我的问题:为iPhone 5扩展应用程序的最佳做法是什么?

Should I make a separate nib now for the 3.5 and 4 inch screen, or extend everything in code?

我现在应该为3.5英寸和4英寸屏幕制作一个单独的笔尖,还是在代码中扩展所有内容?

I'm trying to make this as smooth a transition as possible, so I appeal to knowledge of SO to clue me in onto what the best way is to build for both screens.

我试图尽可能顺利地进行转换,所以我呼吁SO的知识,以便了解为两个屏幕构建的最佳方法。

4 个解决方案

#1


13  

Taking advantage of the full 4" screen in your apps seems to be as simple as adding a new Default image named Default-568h@2x.png with size 640 x 1136. Xcode 4.5 will actually offer to do this for you automatically by adding a black image of the proper size and name to your project.

利用应用程序中的完整4“屏幕似乎就像添加一个名为Default-568h@2x.png且尺寸为640 x 1136的新默认图像一样简单.Xcode 4.5实际上会通过添加一个来自动为您执行此操作适合您项目的大小和名称的黑色图像。

For apps that use standard UI components, such as table views, the tables are magically extended to fill the screen. I updated an app for work and it was literally this simple, with only a couple minor issues related to my own code and UI setup. But all in all, very easy.

对于使用标准UI组件的应用程序(例如表视图),表格会神奇地扩展以填充屏幕。我更新了一个应用程序的工作,它实际上很简单,只有几个与我自己的代码和UI设置相关的小问题。但总而言之,非常容易。

Contrast this with another app I work on (for myself), which uses none of the standard UI components except for UIViews. To deal with both 3.5" and 4" screens, I have had to spend quite a bit of time refactoring code that needs to know screen size for various operations of the app. (The app in this case is more of a game/simulator than say, a productivity app.)

将此与我工作的另一个应用程序(对我自己)进行对比,除了UIViews之外,它不使用任何标准UI组件。为了处理3.5英寸和4英寸屏幕,我不得不花费相当多的时间来重构需要了解应用程序各种操作的屏幕大小的代码。 (在这种情况下,应用程序更像是游戏/模拟器而不是生产力应用程序。)

So, your mileage may vary with regard to the level of effort really required to support the 4" screen. It will depend on how complicated and "non-standard" your app is, as I have discovered.

因此,您的里程可能会因支持4英寸屏幕所需的工作量而有所不同。这取决于您的应用程序有多复杂和“非标准”,正如我所发现的那样。

#2


6  

When updating an existing app for the larger-screen iphone 5, you may also find that the bottom of the screen is not "clickable". For example, if you have a toolbar along the bottom of the screen, that toolbar would be displayed correctly, but buttons would not react to the touch. If this is the case, you need to tell the app that the window is using full screen.

更新大屏幕iphone 5的现有应用程序时,您可能还会发现屏幕底部不是“可点击”的。例如,如果屏幕底部有一个工具栏,则该工具栏将正确显示,但按钮不会对触摸作出反应。如果是这种情况,您需要告诉应用程序窗口使用全屏。

If you have MainWindow.xib, open it, select the window and in the attributes inspector make sure that "Full Screen at Launch" is checked.

如果您有MainWindow.xib,请打开它,选择窗口,然后在属性检查器中确保选中“启动时全屏”。

If you don't have MainWindow.xib in your project (and most newer projects don't), then you need to add one extra line in the applicationDidFinishLaunching of your app delegate:

如果您的项目中没有MainWindow.xib(并且大多数较新的项目没有),那么您需要在appdate的applicationDidFinishLaunching中添加一行:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    [window setFrame:[[UIScreen mainScreen] bounds]];
    ...
}

I put it in the beginning of the method. Worked like a charm.

我把它放在方法的开头。工作就像一个魅力。

#3


3  

You will find this path with simulator XCode->Targets->Summary->iPhone/iPod Deployment Info( the Retina 4-inch )

您将在模拟器XCode-> Targets-> Summary-> iPhone / iPod部署信息(Retina 4英寸)中找到此路径

You need to add a Default image with size 640 x 1136.

您需要添加尺寸为640 x 1136的默认图像。

Apply this code in your AppDelegate file

将此代码应用于AppDelegate文件中

mainWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

mainWindow.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

You will get the main screen size of your window. one more thing whenever you want to check in your class file just add this code

您将获得窗口的主屏幕大小。还有一件事,只要你想要检查你的类文件,只需添加此代码

if ([UIScreen mainScreen].bounds.size.height > 500.0f)

For your view controller just add one property autoresizingMask

对于您的视图控制器,只需添加一个属性autoresizingMask

self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

This works fine for me.

这对我来说很好。

#4


0  

I was looking for the same issue, trying to get iPhone 5 (4") to render my xib files to full screen, and I found this answer, which says you only need to add the Default-568h@2x.png image to tell the iOS that it needs to render your app in 4" fullscreen. just adding this fixed the problem for me.

我正在寻找同样的问题,试图让iPhone 5(4“)将我的xib文件渲染到全屏,我找到了这个答案,说你只需要添加Default-568h@2x.png图像就可以了解它需要以4英寸全屏渲染您的应用程序的iOS。只是添加这个解决了我的问题。

Why [UIScreen mainScreen].bounds] is not returning full screen size?

为什么[UIScreen mainScreen] .bounds]没有返回全屏尺寸?

#1


13  

Taking advantage of the full 4" screen in your apps seems to be as simple as adding a new Default image named Default-568h@2x.png with size 640 x 1136. Xcode 4.5 will actually offer to do this for you automatically by adding a black image of the proper size and name to your project.

利用应用程序中的完整4“屏幕似乎就像添加一个名为Default-568h@2x.png且尺寸为640 x 1136的新默认图像一样简单.Xcode 4.5实际上会通过添加一个来自动为您执行此操作适合您项目的大小和名称的黑色图像。

For apps that use standard UI components, such as table views, the tables are magically extended to fill the screen. I updated an app for work and it was literally this simple, with only a couple minor issues related to my own code and UI setup. But all in all, very easy.

对于使用标准UI组件的应用程序(例如表视图),表格会神奇地扩展以填充屏幕。我更新了一个应用程序的工作,它实际上很简单,只有几个与我自己的代码和UI设置相关的小问题。但总而言之,非常容易。

Contrast this with another app I work on (for myself), which uses none of the standard UI components except for UIViews. To deal with both 3.5" and 4" screens, I have had to spend quite a bit of time refactoring code that needs to know screen size for various operations of the app. (The app in this case is more of a game/simulator than say, a productivity app.)

将此与我工作的另一个应用程序(对我自己)进行对比,除了UIViews之外,它不使用任何标准UI组件。为了处理3.5英寸和4英寸屏幕,我不得不花费相当多的时间来重构需要了解应用程序各种操作的屏幕大小的代码。 (在这种情况下,应用程序更像是游戏/模拟器而不是生产力应用程序。)

So, your mileage may vary with regard to the level of effort really required to support the 4" screen. It will depend on how complicated and "non-standard" your app is, as I have discovered.

因此,您的里程可能会因支持4英寸屏幕所需的工作量而有所不同。这取决于您的应用程序有多复杂和“非标准”,正如我所发现的那样。

#2


6  

When updating an existing app for the larger-screen iphone 5, you may also find that the bottom of the screen is not "clickable". For example, if you have a toolbar along the bottom of the screen, that toolbar would be displayed correctly, but buttons would not react to the touch. If this is the case, you need to tell the app that the window is using full screen.

更新大屏幕iphone 5的现有应用程序时,您可能还会发现屏幕底部不是“可点击”的。例如,如果屏幕底部有一个工具栏,则该工具栏将正确显示,但按钮不会对触摸作出反应。如果是这种情况,您需要告诉应用程序窗口使用全屏。

If you have MainWindow.xib, open it, select the window and in the attributes inspector make sure that "Full Screen at Launch" is checked.

如果您有MainWindow.xib,请打开它,选择窗口,然后在属性检查器中确保选中“启动时全屏”。

If you don't have MainWindow.xib in your project (and most newer projects don't), then you need to add one extra line in the applicationDidFinishLaunching of your app delegate:

如果您的项目中没有MainWindow.xib(并且大多数较新的项目没有),那么您需要在appdate的applicationDidFinishLaunching中添加一行:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    [window setFrame:[[UIScreen mainScreen] bounds]];
    ...
}

I put it in the beginning of the method. Worked like a charm.

我把它放在方法的开头。工作就像一个魅力。

#3


3  

You will find this path with simulator XCode->Targets->Summary->iPhone/iPod Deployment Info( the Retina 4-inch )

您将在模拟器XCode-> Targets-> Summary-> iPhone / iPod部署信息(Retina 4英寸)中找到此路径

You need to add a Default image with size 640 x 1136.

您需要添加尺寸为640 x 1136的默认图像。

Apply this code in your AppDelegate file

将此代码应用于AppDelegate文件中

mainWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

mainWindow.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

You will get the main screen size of your window. one more thing whenever you want to check in your class file just add this code

您将获得窗口的主屏幕大小。还有一件事,只要你想要检查你的类文件,只需添加此代码

if ([UIScreen mainScreen].bounds.size.height > 500.0f)

For your view controller just add one property autoresizingMask

对于您的视图控制器,只需添加一个属性autoresizingMask

self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

This works fine for me.

这对我来说很好。

#4


0  

I was looking for the same issue, trying to get iPhone 5 (4") to render my xib files to full screen, and I found this answer, which says you only need to add the Default-568h@2x.png image to tell the iOS that it needs to render your app in 4" fullscreen. just adding this fixed the problem for me.

我正在寻找同样的问题,试图让iPhone 5(4“)将我的xib文件渲染到全屏,我找到了这个答案,说你只需要添加Default-568h@2x.png图像就可以了解它需要以4英寸全屏渲染您的应用程序的iOS。只是添加这个解决了我的问题。

Why [UIScreen mainScreen].bounds] is not returning full screen size?

为什么[UIScreen mainScreen] .bounds]没有返回全屏尺寸?