如何为iPhone 5屏幕分辨率开发或迁移应用程序?

本文翻译自:How to develop or migrate apps for iPhone 5 screen resolution?

The new iPhone 5 display has a new aspect ratio and a new resolution (640 x 1136 pixels). 新的iPhone 5显示屏具有新的宽高比和新的分辨率(640 x 1136像素)。

What is required to develop new or transition already existing applications to the new screen size? 开发新的或将现有应用程序转换为新的屏幕尺寸需要什么?

What should we keep in mind to make applications "universal" for both the older displays and the new widescreen aspect ratio? 对于旧的显示器和新的宽屏高宽比,我们应该记住什么使应用程序“通用”?


#1楼

参考:https://stackoom.com/question/q0Ya/如何为iPhone-屏幕分辨率开发或迁移应用程序


#2楼

  1. Download and install latest version of Xcode . 下载并安装最新版本的Xcode
  2. Set a Launch Screen File for your app (in the general tab of your target settings). 为您的应用设置启动屏幕文件(在目标设置的常规标签中)。 This is how you get to use the full size of any screen, including iPad split view sizes in iOS 9. 这样便可以使用任何屏幕的完整尺寸,包括iOS 9中的iPad拆分视图尺寸。
  3. Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly, or used Auto Layout. 测试您的应用程序,并希望不执行其他任何操作,因为如果您正确设置了自动调整蒙版的大小或使用了“自动布局”,那么一切都将神奇地工作。
  4. If you didn't, adjust your view layouts, preferably with Auto Layout. 如果没有,请调整视图布局,最好使用“自动布局”。
  5. If there is something you have to do for the larger screens specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] as there seems to be no specific API for that. 如果您需要为较大的屏幕做一些特定的事情,那么您似乎必须检查[[UIScreen mainScreen] bounds]高度,因为似乎没有特定的API。 As of iOS 8 there are also size classes that abstract screen sizes into regular or compact vertically and horizontally and are recommended way to adapt your UI. 从iOS 8开始,还有一些尺寸类,它们可以将屏幕尺寸抽象为垂直或水平方向上的紧凑或紧凑,并且是适应UI的推荐方式。

#3楼

The only really required thing to do is to add a launch image named "Default-568h@2x.png" to the app resources, and in general case (if you're lucky enough) the app will work correctly. 唯一真正需要做的是将名为“ Default-568h@2x.png”的启动图像添加到应用程序资源,并且在通常情况下(如果足够幸运的话),该应用程序将正常运行。

In case the app does not handle touch events, then make sure that the key window has the proper size. 如果应用程序无法处理触摸事件,请确保按键窗口的大小正确。 The workaround is to set the proper frame: 解决方法是设置适当的框架:

[window setFrame:[[UIScreen mainScreen] bounds]]

There are other issues not related to screen size when migrating to iOS 6. Read iOS 6.0 Release Notes for details. 迁移到iOS 6时,还有其他与屏幕尺寸无关的问题。有关详细信息,请参阅iOS 6.0发行说明


#4楼

Here you can find a nice tutorial (for MonoTouch, but you can use the information for Non-MonoTouch-projects, too): 在这里,您可以找到一个不错的教程(用于MonoTouch,但是您也可以将信息用于Non-MonoTouch项目):
http://redth.info/get-your-monotouch-apps-ready-for-iphone-5-ios-6-today/ http://redth.info/get-your-monotouch-apps-ready-for-iphone-5-ios-6-today/

  1. Create a new image for your splash/default screen ( 640 x 1136 pixel ) with the name " Default-568h@2x.png " 为初始屏幕/默认屏幕( 640 x 1136像素 )创建一个新图像,名称为“ Default-568h@2x.png

  2. In the iOS Simulator , go to the Hardware -> Device menu, and select " iPhone (Retina 4-inch) " iOS模拟器中 ,转到“硬件”->“设备”菜单,然后选择“ iPhone(4英寸视网膜)

  3. Create other images, eg background images 创建其他图像,例如背景图像

  4. Detect iPhone 5 to load your new images: 检测iPhone 5以加载新图像:

public static bool IsTall
{
    get {
        return UIDevice.currentDevice.userInterfaceIdiom
                    == UIUserInterfaceIdiomPhone
                && UIScreen.mainScreen.bounds.size.height
                    * UIScreen.mainScreen.scale >= 1136;
    }
}

private static string tallMagic = "-568h@2x";
public static UIImage FromBundle16x9(string path)
{
    //adopt the -568h@2x naming convention
    if(IsTall())
    {
        var imagePath = Path.GetDirectoryName(path.ToString());
        var imageFile = Path.GetFileNameWithoutExtension(path.ToString());
        var imageExt = Path.GetExtension(path.ToString());
        imageFile = imageFile + tallMagic + imageExt;
        return UIImage.FromFile(Path.Combine(imagePath,imageFile));
    }
    else
    {
        return UIImage.FromBundle(path.ToString());
    }
}

#5楼

If you have an app built for iPhone 4S or earlier, it'll run letterboxed on iPhone 5. 如果您有为iPhone 4S或更早版本构建的应用程序,它将在iPhone 5上运行带信箱功能的应用程序。

To adapt your app to the new taller screen, the first thing you do is to change the launch image to: Default-568h@2x.png. 为了使您的应用适应更高的新屏幕,您要做的第一件事是将启动图像更改为:Default-568h@2x.png。 Its size should be 1136x640 (HxW). 其大小应为1136x640(HxW)。 Yep, having the default image in the new screen size is the key to let your app take the whole of new iPhone 5's screen . 是的,在新的屏幕尺寸中具有默认图像是使您的应用占据新iPhone 5整个屏幕的关键

(Note that the naming convention works only for the default image. Naming another image "Image-568h@2x.png" will not cause it to be loaded in place of "Image@2x.png". If you need to load different images for different screen sizes, you'll have to do it programmatically.) (请注意,命名约定仅适用于默认图像。将另一个图像命名为“ Image-568h@2x.png”不会导致将其替换为“ Image@2x.png”。如果需要加载其他图像对于不同的屏幕尺寸,您必须以编程方式进行操作。)

If you're very very lucky, that might be it... but in all likelihood, you'll have to take a few more steps. 如果您非常幸运,也许就是这样...但是很可能, 您将不得不采取更多步骤。

  • Make sure, your Xibs/Views use auto-layout to resize themselves. 确保您的Xib / View使用自动布局来调整自身大小。
  • Use springs and struts to resize views. 使用弹簧和支柱调整视图大小。
  • If this is not good enough for your app, design your xib/storyboard for one specific screen size and reposition programmatically for the other. 如果这对您的应用程序还不够好,请为一种特定的屏幕尺寸设计xib / storyboard,然后针对另一种尺寸以编程方式重新定位。

In the extreme case (when none of the above suffices), design the two Xibs and load the appropriate one in the view controller. 在极端情况下(当以上条件都不满足时),设计两个Xib,然后在视图控制器中加载适当的一个。

To detect screen size: 要检测屏幕尺寸:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        // iPhone Classic
    }
    if(result.height == 568)
    {
        // iPhone 5
    }
}

#6楼

You could add this code: 您可以添加以下代码:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);

            if(result.height == 960) {
                NSLog(@"iPhone 4 Resolution");
            }
            if(result.height == 1136) {
              NSLog(@"iPhone 5 Resolution");
            }
        }
        else{
            NSLog(@"Standard Resolution");
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值