if上的预期标识符(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)

时间:2014-03-25 15:18:15

标签: ios objective-c ios-universal-app

* 这是整个代码:) 我一直试图解决这个问题一小时,但我仍然无法做到。 如果有人能帮助我,我会很高兴:) 仍然无法使UI_USER_INTERFACE_IDIOM代码生效。*

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


-(void)Collision{


if (CGRectIntersectsRect(Heli.frame, Obstacle.frame)) {
    [self EndGame];
}

if (CGRectIntersectsRect(Heli.frame, Obstacle2.frame)) {
    [self EndGame];
}

if (CGRectIntersectsRect(Heli.frame, Bottom1.frame)) {
    [self EndGame];
}

if (CGRectIntersectsRect(Heli.frame, Top1.frame)) {
    [self EndGame];
}





}


-(void)EndGame{

if (Scorenumber > HighScore) {
    HighScore = Scorenumber;
    [[NSUserDefaults standardUserDefaults] setInteger:HighScore     
forKey:@"HighScoreSaved"];
}


Heli.hidden = YES;
[timer invalidate];
[Scorer invalidate];


[self performSelector:@selector(NewGame) withObject: nil afterDelay:2];

}


-(void)NewGame{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    // For iPhone

Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;

Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;

Heli.hidden = NO;
Heli.center = CGPointMake(88, 286);
Heli.image = [UIImage imageNamed:@"buss til app opp.png"];

Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:@"Score: 0"];
Intro3.text = [NSString stringWithFormat:@"HighScore: %i", HighScore];


}
 } else{
    // For iPad
    Bottom1.hidden = YES;
    Top1.hidden = YES;
    Obstacle.hidden = YES;
    Obstacle2.hidden = YES;
    corona.hidden = YES;

    Intro1.hidden = NO;
    Intro2.hidden = NO;
    Intro3.hidden = NO;

    Heli.hidden = NO;
    Heli.center = CGPointMake(153, 515);
    Heli.image = [UIImage imageNamed:@"buss til app opp.png"];

    Start = YES;
    Scorenumber = 0;
    Score.text = [NSString stringWithFormat:@"Score: 0"];
    Intro3.text = [NSString stringWithFormat:@"HighScore: %i", HighScore];

1 个答案:

答案 0 :(得分:1)

请看下面的代码:

-(void)NewGame{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    // For iPhone

Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;

Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;

Heli.hidden = NO;
Heli.center = CGPointMake(88, 286);
Heli.image = [UIImage imageNamed:@"buss til app opp.png"];

Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:@"Score: 0"];
Intro3.text = [NSString stringWithFormat:@"HighScore: %i", HighScore];


}
 } else{

并看 - " }"符号之前" } else{"是错的。

是一对
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

开放建设,所以"否则"是独立的 - 这是错误的。 尝试删除此" }"。