iPhone 3.5英寸屏幕 - 4英寸屏幕: [英] iPhone 3.5 Inch screen - 4 inch screen:
问题描述
我知道您可以使用带有 UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad
的if语句来选择ipad或iphone。但我想知道你是否可以为iPhone 3.5英寸屏幕iPhone 4英寸屏幕做同样的事情。我有一款游戏最初是为iPhone 4英寸屏幕设计的,但是自动布局已用于修复两个设备之间的错误,我需要改变的一件事就是当
I know you can choose ipad or iphone by using an if statement with UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
. But I was wondering if you could do the same for iPhone 3.5 inch screen to iPhone 4 inch screen. I have a game which was originally designed for the iPhone 4 inch screen, but auto layout has been used to fix the errors between the two devices, the one thing I need to change is that when
if (ball.center.y > 600) {
RandomPosition = arc4random() %248;
RandomPosition = RandomPosition + 36;
ball.center = CGPointMake(RandomPosition, -22);
}
因为它最初是在4英寸屏幕上设计的,所以游戏设置完毕当球大于600像素时,将球重置到屏幕顶部,这正好在iphone 4英寸屏幕下方。它仍能正常工作,3.5英寸屏幕底部和位置重置之间只有一点延迟。无论如何我可以用 UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiom(iphone4 ???)
设置一个if语句来设置一个新的ball.center.y> 300或者其他什么东西?
Because it was originally designed on the 4 inch screen, the game is set up to reset the ball to the top of the screen when it is > 600 pixels, which is just below the iphone 4 inch screen. It still functions properly, there is just a bit of a delay between the bottom of the 3.5 inch screen and the resetting of the position. Is there anyway I could set up an if statement with UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom(iphone4???)
to set up a new ball.center.y > 300 or something?
推荐答案
您可以尝试以下代码。
在Constant.h中添加此代码
You can try following code. Add this code in Constant.h
#define IS_IPAD (( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) ? YES : NO)
#define IS_IPHONE_5 (([UIScreen mainScreen].scale == 2.f && [UIScreen mainScreen].bounds.size.height == 568)?YES:NO)
#define IS_RETINA_DISPLAY_DEVICE (([UIScreen mainScreen].scale == 2.f)?YES:NO)
现在检查设备大小在您的视图中添加以下代码
Now to check the device size add the following code in your Views
if (IS_IPAD)
{
//do stuff for iPad
}
else
{
if(IS_IPHONE_5)
{
//do stuff for 4 inch iPhone screen
}
else
{
//do stuff for 3.5 inch iPhone screen
}
}
这篇关于iPhone 3.5英寸屏幕 - 4英寸屏幕:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!