I build the app for iphone, it is running well on the 4 inch screen, but whenever I try to run it on the3.5 inch thr bottom part gets cut off. Can somebody tell me what I'm doing wrong? Thanks
You must be manually setting sizes and locations. Instead, if you dynamically set the locations and sizes based on size of the screen it should work.
BAD example:
Label.position = CGPointMake(100, 300);
GOOD example:
Label.position = CGPointMake(self.size.width/3, self.size.height/3);
Just set a playable area (to avoid the screen being truncated) and use
self.scaleMode = SKSceneScaleModeAspectFill
I had the same problem when making my first simple Sprite Kit game. Work began on an iPhone 5S (4 inch screen), but when the game was loaded onto an iPhone 4S (3.5 inch screen) the screen was cut off. Here's the code, that I wrote inside my methods when needed, that fixed it for me:
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480)
{
NSLog(#"Old iPhone detected");
//Write what ever code you need for the 3.5 inch screen here.
}
else
{
NSLog(#"New iPhone detected");
//Write what ever code you need for the 4 inch screen here.
}
Related
I have a Universal iOS app and am trying to move from old-style launch images to a simple centered image on a storyboard Launch screen, so I have a single storyboard for all devices. My image (640x1136, iPhone 5s size) needs to not be stretched when the app is run on devices with larger sizes than the image -- in other words, the background color of the UIView should appear surrounding the image on larger devices. For debugging purposes I changed the view background color to a gaudy Lime.
I defined 2 constraints on the UIImageView as directed in the SO post here according to the highest-upvoted answer (Suragch's) and in fact had to also follow the accepted answer's recommendation to add the additional UIView into which my UIImageView would be contained.
The "content mode" of the UIImageView is Center so seems there should be no stretching.
In the pic notice Xcode's Size Inspector settings for the UIImageView. The UIView has iPhone 7-sized dims (750x1334) and so because that iPhone is taller than my image the UIImageView is positioned so that its X is 55, Y is 99. The width and height are same as the image itself (640x1136).
When I run in Simulator an iPhone 7 seems it should look like exactly as what Xcode's Interface Builder shows (Lime color appearing all around the image, but instead, for any device larger than an iPhone 5s or SE it looks like the pic I've attached (an iPad Air, FYI). You can tell the image must be stretched quite a bit vertically because the image is only 1136 tall.
I've attached screenshots for the iPhone 7 (simulator) iPad Air and iPad Pro. Notice the horizontal strips of lime color appear on the right and left edges of the iPad Air. And notice that when it comes to the iPad Pro the lime background color begins to be shown above the image. It's as if on the smaller devices the system is stretching the UIImageView, but as device screen size increases this eventually stops, until for the largest (the Pro) you can actually see the background all around. It seems that for all device sizes listed in the Apple docs that are taller than iPhone 5s or SE, there should be no stretching/distortion. This is what I'm trying to accomplish.
Interface Builder size settings
iPhone 7 (simulator) screenshot
iPad Air (device) screenshot
iPad Pro (device) screenshot
I was able to get this to work finally, by completely eliminating the constraints and only using the autoresizing settings found when you choose the Size Inspector. The UIImageView now retains its specified size and is not stretched.
Try adding a width/height constraint to your ImageView:
This is done by first selecting your ImageView and then selecting this |-☐-| icon (located at the bottom right of the Storyboard window, next to the option where you can change the type of device)
Okay, I think I've figured out the problem. Your image is sized too large. You say you want it to be the size of an iPhone 5, and it's display size is 1136x640 pixels. This is not the same as the width/height in Xcode. To get this, change the device to iPhone 5 (or similar) and get the size. For instance, the size of the View for an iPhone 8 is 667x375. Then your image won't be cut off.
I'm making a game for the iPhone and iPad and I don't understand how when I position my menu on the iPhone 5s it looks different on the iPad. Like my score it is set perfectly in the score menu on the 5s and 4 and 5 but in the iPad its a little lower and not the same positioning. How do I fix this? Thanks! I use this code to position my menus:
endOfGameHighScoreLabel.position = CGPointMake(self.size.width / 1.8,
self.size.height / 2.7)
ahm with self.size.width you don't get the size of the view but the label?
I would recommend to create a view containing all the game over stuff you need and then position the center of it in the view's center:
gameOverView.center = CGPointMake(self.view.frame.width/2, self.view.frame.height/2)
I am creating a Universal App.
I have created my art in illustrator to fit properly on an iPhone screen, specifically at 640x1136 px. I exported PNGs and named myArt#2x.png and also a 50% version named myArt.png. The art is in an atlas folder.
I am creating sprite nodes a like this:
NSString * backgroundName=#"starField";
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:backgroundName];
background.position = CGPointMake(screenWidth/2, screenHeight/2);
background.zPosition = LayerBackground;
[_worldNode addChild:background];
The problem is that when I run this in the simulator (iPhone 4 w/retina), the images are scaled up. I have to ousel xScale and yScale to bring it back to actual size.
Why? What am I doing wrong?
Thanks,
rich!
You need to set the size property of the SKNode I think. For example:
background.size = CGSizeMake(screenWidth, screenHeight);
Okay I think I solved it -
I don't start creating my content until viewWillLayoutSubviews had been called. The default SpritKit Template uses viewDidLoad, but I changed that to viewWillLayoutSubviews and everything looks fine now.
I think I was trying to create stuff before the view "sorted" itself out...
Not sure what the difference is but it worked.
-r
I've been working on an app that was for 4 inch screens but I found out that I have to make it compatible with 3.5 inch displays too, i searched for solutions but they didnt work for me i still get the clipped part at the bottom
sorry if my question is stupid im still new to Xcode environment and programming in general.
I used 4 inch screen's condition for the same problem. first define this as
#define IS_IPHONE_5 ( [ [ UIScreen mainScreen ] bounds ].size.height == 568 )
Then i used this condition to set frames of IBOutlet for 4inch screen and 3.5 inch screen as
if(IS_IPHONE_5)
{
//set frames as per 4 inch screens
}
else
{
//set frames as per 3.5 inch screens
}
This will help you to design for different size screens of iphone.
Autolayout has to be enabled in your views (even cells)
You have to make your images (backgrounds) 1136x640 (HxW) too
This information has been answered many times before, you can read more specific info: Here
My app have a background image that fills the screen. I'd like to display the correct .png file depending on if we're on a Retina Display device or not. I already have added all the .png files for both iPhone and iOS with the correct sizes. Is it possible ? If not, how should I handle it properly ?
I have XCode 4.3.2 with iOS 5.1 as the deployment target.
If you name your graphics properly (e.g. add "#2x" to the suffix of the png files), iOS is smart enough to use your Retina display graphics on the appropriate devices & displays. Especially if you are using UIImageViews or controls or whatever, within your user interfaces designed within XIB files.
If you're doing programmatic images (i.e. where you define an outlet and then grab an image via something like "[UIImage imageNamed:], iOS is still smart enough to pick up the high rez images for you. Again, provided you named your graphics properly.
There are other questions here on StackOverflow that might help you out, such as:
How to support both iPad and iPhone retina graphics in universal apps
How to activate #2x high res graphics for retina display?
This probably would work. First it checks if the screen has a retina display, and if it does, sets the background image to the retina image. If it does not have a retina display, the background image is the regular image. You can put this in viewWillAppear or viewDidLoad.
if ([[UIScreen mainScreen] respondsToSelector:#selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
// Retina display
UIImage *backgroundImage = [UIImage imageNamed:#"retinaImage.png"];
} else {
// Non-Retina display
UIImage *backgroundImage = [UIImage imageNamed:#"nonRetinaImage.png"];
}
Hope this helps!