我试图通过运行下面的代码来检测应用程序运行的iPhone,但是我得到了一个预期的表达式错误
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
然后我将这些用于使用:
if(IS_IPAD)
{
NSLog(@"IS_IPAD");
}
if(IS_IPHONE)
{
NSLog(@"IS_IPHONE");
}
if(IS_RETINA)
{
NSLog(@"IS_RETINA");
}
if(IS_IPHONE_4_OR_LESS)
{
NSLog(@"IS_IPHONE_4_OR_LESS");
}
if(IS_IPHONE_5)
{
NSLog(@"IS_IPHONE_5");
}
if(IS_IPHONE_6)
{
NSLog(@"IS_IPHONE_6");
}
if(IS_IPHONE_6P)
{
NSLog(@"IS_IPHONE_6P");
}
然后是代码:
bool MainScene::init()
{
if ( !CCLayer::init() )
{
return false;
}
MyGameBridge::showBanner();
g_nScore = 0;
r = 72;
g = 180;
b = 187;
CCLayerColor *background = CCLayerColor::create(ccc4(r, g, b, 255), G_SWIDTH, G_SHEIGHT);
this->addChild(background, 0);
newSprite("ground", G_SWIDTH/2, G_SHEIGHT / 2, this, 2, RATIO_XY);
newSprite("Player", G_SWIDTH/2, getY(855), this, 0, RATIO_X);
// newSprite(CCString::createWithFormat("bg_main%d_en", graphics_mode)->getCString(), G_SWIDTH/2, G_SHEIGHT/2, this, 0, RATIO_XY);
CCMenuItemToggle* btnSound=newToggleButton("sound", G_SWIDTH/2 - getX(150), getY(650), this, menu_selector(MainScene::onClickSound), true, RATIO_X);
btnSound->setSelectedIndex(g_bSound?0:1);
CCMenuItemImage *scoreItem=newButton(CCString::createWithFormat("btn_score")->getCString(), G_SWIDTH/2 + getX(150), getY(650), this, menu_selector(MainScene::onClickScore), true, RATIO_X);
scoreItem->setScale(G_SCALEX*0.95);
// scoreItem->setScaleY(G_SCALEY*0.9);
// sets the postion, and image of the play button
CCMenu* menu;
menu = CCMenu::create(
newButton(CCString::createWithFormat("Play")->getCString(), G_SWIDTH/2, getY(500), this, menu_selector(MainScene::onClickPlay), true, RATIO_X),
scoreItem,
btnSound,
NULL);
menu->setPosition(0, 0);
this->addChild(menu);
if(IS_IPHONE_6P) // Here is where the expression error occurs
{
NSLog(@"IS_IPHONE_6P");
}
//adds the title
newLabel(CCString::createWithFormat("Pop Up!")->getCString(), CCString::createWithFormat("DINAlternate-Bold")->getCString(), 200, G_SWIDTH / 2, getY(150), this, 2, RATIO_Y);
// adds the highscore title
newLabel(CCString::createWithFormat("Best: %d", g_nBestScore)->getCString(), CCString::createWithFormat("Arial")->getCString(), 85, G_SWIDTH / 2, getY(270), this, 2, RATIO_Y);
return true;
}
我需要修理/编辑什么?