[英]How do I implement macros for IOS 7?
I trying to make universal app for all IOS devises except for iPhone below 4 and I have this macros that work for IOS 8: 我试图为所有IOS设计制作通用应用程序,但iPhone 4以下的除外,我有适用于IOS 8的以下宏:
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON )
#define IS_IPHONE_6 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1334 ) < DBL_EPSILON )
here is the code I am using: 这是我正在使用的代码:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
SKSpriteNode *background;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (IS_IPHONE_6) {
background = [SKSpriteNode spriteNodeWithImageNamed:@"Background-667"];
}
else if (IS_IPHONE_5) {
background = [SKSpriteNode spriteNodeWithImageNamed:@"Background-568"];
}else{
background = [SKSpriteNode spriteNodeWithImageNamed:@"Background"];
}
}else{
background = [SKSpriteNode spriteNodeWithImageNamed:@"Background~iPad"];
}
background.anchorPoint = CGPointMake(0.5, 1);
background.position = CGPointMake(self.size.width/2, self.size.height);
[self addChild:background];
}
return self;
}
but these macros doesn't work for IOS 7 to detect optimized images. 但是这些宏不适用于IOS 7来检测优化的图像。 In this forum How to detect iPhone 5 (widescreen devices)?
在此论坛中如何检测iPhone 5(宽屏设备)? they say you need to put this code and it will work
他们说您需要输入此代码,它将起作用
#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 )
but when I do the app crashes. 但是当我这样做时,应用程序崩溃了。
What do I need to add to make it work? 我需要添加什么才能使其正常工作? I am a beginner developer and dont understand how this macros work.
我是新手开发人员,不了解此宏的工作原理。
The macro IS_WIDESCREEN
is written correctly because it asks the system if it can responds to the message -nativeBounds
. 正确编写了宏
IS_WIDESCREEN
,因为它询问系统是否可以响应消息-nativeBounds
。
For IS_IPHONE_6
and 5 you should write something like the widescreen macro, -nativeBounds
was only implemented in iOS8 that's why it crashes if you launch your app on iOS7. 对于
IS_IPHONE_6
和5,您应该编写宽屏宏之类的东西, -nativeBounds
仅在iOS8中实现,这就是如果您在iOS7上启动应用程序时崩溃的原因。
Probably using images asset in Xcode you can achieve what you want by simply creating an images asset that load different image for different screen size. 可能使用Xcode中的图像资源,您可以通过简单地创建一个图像资源来实现所需的目标,该图像资源针对不同的屏幕尺寸加载不同的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.