简体   繁体   中英

Can anyone help me with this xcode issue?

I'm trying to get my app to display properly on the iPad as when I run it the text position;

label.position = CGPointMake(-180, -135);

Which is set for the iPhone res position but of course when running on the iPad the position is completely off (still in the same place for the iPhone one).

Is there anything I can add for it to auto resize the position if an iPad is detected?

The full code I have atm is as follows!;

SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
label.fontSize = 14;
label.fontColor = [SKColor yellowColor];
label.text = @"-Shield Power-";
label.position = CGPointMake(-180, -135);
label.alpha = 1;
[self addChild:label];

You have, somehow, to detect if you are running on an iPad or an iPhone. Then implement an if statement for the position.

  UIDevice* thisDevice = [UIDevice currentDevice];
    if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        // iPad
    }
    else
    {
        // iPhone
    }

That being said, you could also try autolayout and constraints. You can have two storyboards (one for each device) and set views separately.

You want to use the CGGeometry class - https://developer.apple.com/library/ios/documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html - this will enable you to do things like:

CGRectGetWidth(self.view.frame);

and

CGRectGetMinY(self.view.frame);

And then construct X and Y co-ordinates for your CGPoint, eg

CGPointMake(CGRectGetMinX(self.view.frame)-180,CGRectGetMinY(self.view.frame)-135);

or using percentages so that everything happens in a dynamic way, like this:

CGPointMake(CGRectGetMinX(self.view.frame)-CGRectGetWidth(self.view.frame)*0.5,CGRectGetMinY(self.view.frame)-CGRectGetHeight(self.view.frame)*0.3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM