简体   繁体   English

使应用程序与iPhone4和iPhone5兼容,而无需设置不同的帧大小

[英]Making application compatible with iPhone4 and iPhone5 without setting diffrent frame size

Today i am going to create an iphone application which is compatible with iphone4 and iphone5. 今天,我要创建一个与iPhone4和iPhone5兼容的iPhone应用程序。 Earlier i have changed iphone4 application views programetically by using below code to adjust controllers for iphone5. 之前,我通过使用以下代码来调整iphone5的控制器,从而以编程方式更改了iphone4应用程序视图。

 CGRect screenBounds = [[UIScreen mainScreen] bounds];
 if (screenBounds.size.height == 568) {
 // code for iphone5
 }
 else {
 // code for iphone4
 }

am thinking this is difficult to track all the frames and sizes of controllers each and every time. 我认为很难每次都跟踪控制器的所有框架和大小。 I have created one sample app and also tried with Auto-resizing option(i have put check mark) at the starting of view and selected size Retina 4 full screen in inspector. 我创建了一个示例应用程序,还尝试在视图开始时使用“自动调整大小”选项(我已勾选了),并在检查器中选择了全尺寸的Retina 4。 And also selected simulator hardware-device is iphone Retina-4 inch 并且还选择了模拟器硬件设备是iphone Retina-4英寸

为iPhone5选择

if i change simulator hardware-device is iphone Retina-3.5 inch then the screen is looking like 如果我更改模拟器硬件设备为iPhone Retina-3.5英寸,则屏幕看起来像

为iPhone4选择

My question is without setting frames how can i achieve this problem. 我的问题是不设置框架如何解决此问题。 Please help me. 请帮我。 Thanks in advance. 提前致谢。

You can use this link for autosizing 您可以使用此链接自动调整大小

http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/ http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/

Instead of giving static numbers give frames dynamically . 与其给出static数字,不如给出dynamically帧。 means instead of giving 320 give self.view.frame.size.width so you no need to check the device, just you need to add default splash screen. 意味着不必给320提供self.view.frame.size.width因此您无需检查设备,只需要添加默认启动屏幕即可。

You problem could be resolved easily using Autolayout feature provided in the XCode Version 4.x . 使用XCode版本4.x中提供的自动布局功能可以轻松解决您的问题。 Go through the following link :- 通过以下链接:-

http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2 http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

By applying few contraints using Autolayout your problem could easily be resolved. 通过使用“自动布局”应用少量约束,可以轻松解决问题。 Happy Coding :) 快乐编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM