如何检测IOS 7和IOS 8以及宽屏iPhone尺寸以使我的应用程序具有通用性? [英] How to detect IOS 7 and IOS 8 and widescreen iPhone sizes to make my app universal?

查看:129
本文介绍了如何检测IOS 7和IOS 8以及宽屏iPhone尺寸以使我的应用程序具有通用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为所有设备和IOS 7和IOS 8开发通用的IOS应用程序。我有这个宏:

I am developing universal IOS app for all devices and IOS 7 and IOS 8. and I have this macros:

这个宏用于检测宽屏iPhone 5,这个适用于IOS 7:

This macros is for detecting widescreen iPhone 5, this works for IOS 7:

#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

此宏也用于宽屏iPone 5,但有效仅适用于IOS 8:

This macros is also for for widescreen iPone 5, but works only for IOS 8:

#define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON )

我需要结合使用这段代码才能使它同时工作IOS 7和IOS 8为此我需要选择器来检测IOS版本。这里是代码:

I need to combine this code to make it work on both IOS 7 and IOS 8and for that I need selector that detects IOS version., here is the code:

#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON )
#define IS_WIDESCREEN      ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_WIDESCREEN_IOS8 : IS_WIDESCREEN_IOS7 )

然后该帖子的作者建议引用 - 如果您还针对iOS 7或更低版​​本,请务必使用功能检测,因为在iOS 8之前调用nativeBounds会导致您的应用崩溃: 并提供以下代码:

then the author of the post suggests to quote -"If you're also targeting iOS 7 or lower, be sure to use feature detection, as calling nativeBounds prior to iOS 8 will crash your app:" and gives following code:

if( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] )
{
    /* Detect using nativeBounds - iOS 8 and greater */
}
else
{
    /* Detect using bounds - iOS 7 and lower */
}

请在这里帮助我我是一名初学者,希望了解如何使其发挥作用。我应该在哪里放SKSpriteNode * background = [SKSpriteNode spriteNodeWithImageNamed:@Background];?

Please help me here I am a beginner developer and want to understand to to make it work. Where should I put SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Background"];?

所有这些代码来自Stackoverflow帖子中的不同帖子这里是:如何检测iPhone 5(宽屏设备)?

All this code is from different post in Stackoverflow post here is it: How to detect iPhone 5 (widescreen devices)?

我上传图片到投递箱这里是链接 https://www.dropbox.com/sh/pnll2e2jvo0uigs/AACOLbzzQqZlJEZZcBx7TMR1a?dl=0 该文件夹名为measuredImages。这是我用来添加背景的代码:#importGameScene.h

I uploaded images to drop box here is the link https://www.dropbox.com/sh/pnll2e2jvo0uigs/AACOLbzzQqZlJEZZcBx7TMR1a?dl=0 the folder is called measuredImages. here is the code I use for adding background: #import "GameScene.h"

@implementation GameScene
-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Background-568"]; background.anchorPoint = CGPointMake(0.5, 1);
        background.position = CGPointMake(self.size.width/2, self.size.height);
        [self addChild:background];}
    return self;
}

如果有人可以把完整的代码用宏和用法回答我会非常感激它。

If someone could put full code with macros and usage in answer I would greatly appreciate it.

重要
更新:12.17.2014

Important UPDATE:12.17.2014

这个问题通过包含权利解决了正如Daij-Djan建议的那样,启动图像和我的应用以正确的分辨率运行,我使用了屏幕边界[与ios7相同]。感谢所有试过或帮助我解决这个问题的人,我个人要感谢Daij-Djan和sha的帮助和支持。如果您需要宽屏iphone的代码,我将在下面的答案中留下它,它可以在iPhone 4和所有iPad上面的所有iPhone上运行。

This problem was solved by including the right launch images and my app run in the right resolution and I used screen bounds [same as in ios7], as Daij-Djan suggested. Thanks to everybody who tried or helped me to solve this problem,I personally want to thank Daij-Djan and sha for help and support. If you need the code for widescreen iphones I will leave it in my own answer below, it runs on all iPhones above iPhone 4 and all iPads.

推荐答案

你不需要专门检测屏幕宽度。



只包括正确的启动图像,你的应用程序将以正确的分辨率运行你可以使用屏幕边界[与ios7相同]

you don't need to go os specific for detecting the screen width.

just include the right launch images and your app will run in the right resolution and you can just use the screen bounds [same as in ios7]

我再次强调:包括正确的发布图像!
然后使用 UIScreen边界

I stress again: include right launch images! THEN use the UIScreen bounds

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LaunchImages.html

这篇关于如何检测IOS 7和IOS 8以及宽屏iPhone尺寸以使我的应用程序具有通用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆