So for some reason, whenever I run an ipad simulator in xcode, it does not recognize that it is running as an ipad and pulls the background image for the iphone on the ipad. This makes it look really stretched and distorted.
Here is part of my code from my ISUtilsPack.h:
//device type definition
#ifdef UI_USER_INTERFACE_IDIOM
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#else
#define IS_IPAD false
#define IS_IPHONE true
#endif
And here is my code from my UIManager.m:
//background image
+ (UIImage *)mainBackgorundImage
{
UIImage *image = [UIImage imageNamed:#"iphone-568"];
if(IS_IPAD)
image = [UIImage imageNamed:#"ipad"];
return image;
}
Every time xcode is pulling the iphone-568 image for the background and not the ipad image even when running the simulator for ipad. Does anybody know why this is?
Thanks!
Related
I have an iPhone app I am testing on my iPhone and iPad. When running my app adhoc, the problem is that when the photo loads on my iPhone 4 during ad hoc testing, the photo loads on its side; the photo loads fine on iPad mini.
The following line of code successfully rotates the fullscreen image on iPhone, but conversely rotates the image when I test on iPad.
//successfully rotates but also over rotates on iPad
PhotoView.transform=CGAffineTransformMakeRotation(M_PI*0.5);
Can someone help me set up conditional statements so I can use my CGAffineTransforMakeRotation line of code only on iPad?
I have so far tried the following conditional statements but they don't work for some reason: i.e. only the iPhone if statement works and overrides the iPad if statement so the iPhone statement is carried out on both devices.
//does not successfully set the bk for iPad but does for iPhone. The iPad statement is overridden and the iPhone statement is carried out on both platforms. Any ideas?
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
}
This second conditional statement also doesn't work...
if ([[UIScreen mainScreen] bounds].size.height == 480)
{
// iPhone, iPod Touch
}
if ([[UIScreen mainScreen] bounds].size.height == 568) {
// iPhone 5
}
if ([[UIScreen mainScreen] bounds].size.height == 667) {
// iP6
}
if ([[UIScreen mainScreen] bounds].size.height == 736) {
// iP6+
}
if ([[UIScreen mainScreen] bounds].size.height == 1024) {
// iPad
}
My question: does anyone have code to rotate an image on iPhone but not iPad?
If it's an iPhone app, it is always "on an iPhone". Even when running on the iPad, it is running on a virtual iPhone in emulation mode. It is impossible for it to behave differently on the different devices; it is running on just one device type, as far as it can tell.
If you don't like that, make it a Universal app. Now it runs natively on iPad and your tests will work.
I'm using Xcode 6 and use objective-c when i test program on iOS 8 (iPhone 5) program run without error but when i try to test program on iOS 7 (iPhone 5) screen look like iPhone 4 screen. I can detect phone like this;
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)
#define IS_IPHONE_5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
#define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
and also i can detect operating system like this;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_0)
{
#define IS_IPHONE_5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
}
When i do this screen not scale on phone because when i run on iOS 7 phone screen run like iPhone 4 check image for more description.
As you can see top and bottom black.How can i fix this problem
Set an iPhone 5 launch screen. It will be fixed.
iPhone 5 launch screen spec: 640x1136
For the time being create a blank screen on photoshop or preview. You can replace it later.
I am trying to make a universal app for iPhone. I have a few #define values in my *.m file
#define VERTICAL_GAP_SIZE 120
#define FIRST_OBSTACLE_PADDING 100
#define OBSTACLE_MIN_HEIGHT 60
#define OBSTACLE_INTERVAL_SPACE 130
down in the code it is being used like this (and whole lot other places)
...
float maxVariance = availableSpace - (2*OBSTACLE_MIN_HEIGHT) - VERTICAL_GAP_SIZE;
Now these values are all good if I am running my app on a iphone. For iPad I want to change these values, I just don't know how? I mean if I try this its a compiler error.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
//its iphone
}
else
{
//its ipad
VERTICAL_GAP_SIZE = 120
}
I don't want to create new #define just for iPad as these values are being used in a lot of places in my code.
Well you can't really, since a #define is precompile marco and is not available at run time when you are checking for the userInterfaceIdiom.
I have an app which is developed for iPhone only. When user runs it on iPAD
it is not showing properly. I know how to detect "IS_iPAD" when project is universal but
when project is iPhone specific the USER DEVICE is always returned as iPhone.
How one can detect if iPhone specific application is run on iPAD?
For sake of completion here is the #MichaelPatzer answer pointed by #user42949
If the app is an iPhone app running in the emulator mode on an iPad,
it will have a userInterfaceIdiom of Phone, but a model type of iPad.
You can check this with the following code:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
[[[UIDevice currentDevice] model] hasPrefix:#"iPad"]) {
// This app is an iPhone app running on an iPad
}
You can use this different macro to know if you are using iPhone, iPhone 5 or iPad :
#define IS_IPHONE() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE5() ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && [UIScreen mainScreen].bounds.size.height == 568)
Another option, if your code is layout-specific (which is how I got here):
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGFloat screenRatio = MIN(screenSize.width / screenSize.height, screenSize.height / screenSize.width); // account for rotation
if(screenRatio > 6.65 && screenRatio < 6.67) {
// iPad is 6.66666
}
What is the new naming convention for images for the 4-inch retina display?
For an image named background.png you add #2x to the name (background#2x.png) to tell iOS to use that one for devices with the retina display.
What would the suffix be for iPhone 5's screen size?
You can use my #defines to help you with these images:
#define isPhone568 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
#define iPhone568ImageNamed(image) (isPhone568 ? [NSString stringWithFormat:#"%#-568h.%#", [image stringByDeletingPathExtension], [image pathExtension]] : image)
#define iPhone568Image(image) ([UIImage imageNamed:iPhone568ImageNamed(image)])
Just give your images the -568h#2x.png notation, and use iPhone568ImageNamed to get a name for standard name or iPhone 5/new iPod.
Usage example from the comments:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:iPhone568ImageNamed(#"mainscreen.png")]];