如何将UIUserInterfaceIdiomPad应用于此?

时间:2014-09-09 19:32:59

标签: ios sprite-kit

我已经为另一个hud做了一个,但这段代码我没有线索

for (int i=0; i < hud.lives; i++) {
        SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"Sprites"];
        SKTexture *hlife = [atlas textureNamed:@"HUD_life_1"];
        SKSpriteNode *lifeBar = [SKSpriteNode spriteNodeWithTexture:hlife];
        lifeBar.name = [NSString stringWithFormat:@"Life%d",i+1];

        [hud addChild:lifeBar];

        if (lastLifeBar == nil ) {
            lifeBar.position = CGPointMake(catHead.position.x+30, catHead.position.y);
        } else {
            lifeBar.position = CGPointMake(lastLifeBar.position.x+10, lastLifeBar.position.y);
        }

        lastLifeBar = lifeBar;
    }

1 个答案:

答案 0 :(得分:2)

为什么不使用像这样的简单宏:

如果当前设备是iPad,则检查(编译时),如果是,则返回yes,否则返回:

#define IS_IPAD() ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

在这里,你可以设置你想要的高度使用上面的宏。如果当前设备是iPad,则值为55,否则为44:

#define MY_HEIGHT  (IS_IPAD() ? 55 : 40)

并将此作为奖励;):

如果当前设备是iPhone5 / iPhone5c / iPhone5s,这个将检查(编译时),如果是,则返回yes,否则为:

#define IS_IPHONE_5 ( [ [ UIScreen mainScreen ] bounds ].size.height == 568 )