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.
Related
Based on the following image:
I want the green and red text to shrink for the 4 inch screen size, but not for the 4.7 inch size.
What I did is set the Autoshrink property to Minimum Font Scale - 0.7 and also changed the labels Lines property to 0.
Now the font shrinks for the 4 inch screen, but also for 4.7 one, which I don't want too. How do I prevent the text to shrink for a specific screen ?
Is there a way to do this using Size Classes ? Or I have to do something in code to check for the specific screen size ?
You can't use Size Classes to distinguish iPhone 4 vs iPhone 4.7. Size Classes can only distinguish these cases (see picture below). You must check the specific screen size in you code
I think that you can use this code to identify device size:
(#)define iOSVersionGreaterThanOrEqualTo(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
in Header file (.h)
+(NSString*)deviceSize {
CGFloat screenHeight = 0;
if (iOSVersionGreaterThanOrEqualTo(#"8")) {
screenHeight = MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
}else
screenHeight = [[UIScreen mainScreen] bounds].size.height;
if (screenHeight == 480)
return "Screen 3.5 inch";
else if(screenHeight == 568)
return "Screen 4 inch";
else if(screenHeight == 667){
if ([UIScreen mainScreen].scale > 2.9) return Screen5Dot5inch;
return "Screen 4.7 inch";
}else if(screenHeight == 736)
return "Screen 5.5 inch";
else
return "UnknownSize";
}
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 am trying to build a version of my app specifically for iPhone 6 and 6 Plus , whereas I don't have any hardware , I have to test on the simulator ! but it seems , simulator has a strange bug ! first and for most I get screen resolutions and scales , by this code :
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(#"Screen bounds: %#, Screen resolution: %#, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
so here is how detect iPhone 6 and 6Plus (Portrait mode):
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)
the problem is ! when I lunch my app on iPhone6/Plus simulator , compiler gives me the sceen information of iPhone 4" display :
2014-09-28 12:32:08.153 WOD[2924:42290]
Screen bounds: {{0, 0}, {320, 568}}, Screen resolution: <UIScreen: 0x7fa15be0f9b0; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7fa15bd0d4a0;
size = 640.000000 x 1136.000000>>, scale: 2.000000, nativeScale: 2.000000
But it works fine on new project ! (I cannot create a new project and start over again !).
I cleaned code , delete build folder , change project's name ,and reset Simulator contents setting but still gives me the information of 4" display ! .
I have checked this Q/A but answers require a real device !
The main reason I faced with this problem was I build my application with Xcode 5 and open it with Xcode 6
Solution :
Add Launch Image for Retina HD 5.5 and 4.7 :
Now you can detect iPhone 6/Plus on simulator without having a real device :
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)
Just in case you need to detect iPhone 6/6Plus in landscape, use this.
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)
I am attempting to detect whether the current device is iPhone5, iPhone6 or iPhone 6 Plus.
In my app I am already using this macro to detect iPhone 5 which works perfectly.
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
Similarly, I use this macro to detect iPhone 6 and iPhone 6 Plus.
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6_PLUS (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)
The IS_IPHONE_5 macro works as expected in any orientation.
My problem is that the IS_IPHONE_6 and IS_IPHONE_6_PLUS macros do not return true when the device is held in LANDSCAPE. However they do work as expect while the device is held in PORTRAIT. What gives?
Also if anyone has a better recommendation to detect iPhone5, 6 and 6 Plus please share.
This is tested and designed for any combination of iOS system versions and SDK versions
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
Note: If iPhone 6 is in zoomed mode the UI is a zoomed up version of iPhone 5. This is reflected in the macros.
Usage: http://pastie.org/9687735
Don't use the screen size for this, it's better to use the hardware model. We are getting more and more screen sizes every year, the less you hard-code screen dimensions in your code the better for your future self.
You need a helper function to get the machine name. I'm using dispatch_once to avoid querying the system multiple times for data that won't change.
NSString* machineName()
{
static NSString* name = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
struct utsname systemInfo;
uname(&systemInfo);
name = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
});
return name;
}
Then define a few macros as needed:
#define IS_IPHONE_6 [machineName() isEqualToString:#"iPhone7,2"]
#define IS_IPHONE_6_PLUS [machineName() isEqualToString:#"iPhone7,1"]
For some models is trickier:
#define IS_IPHONE_5s [machineName() hasPrefix:#"iPhone6,"]
Finally, use the macros in your code:
if (IS_IPHONE_6) {
// for the 6
}
Note: This answer your question (detect models with macros) but you're doing it wrong IMHO. You should use autolayout and size classes, unless you support really old iOS versions...
Take a look at this answer: iOS - How to get device make and model? it doesn't use macros but it does the job. I've seen some similar problems with macros to detect iPhone 6 and iPhone 6 plus. So it would be a better idea to try out the answer from #Ohhmee
EDIT: Of course there probably is a solution detecting it with macros. But I don't know that and I can't find a solution so i'm suggesting a different approach.
Your macros are ridiculous and seem to indicate a fear of floating-point arithmetic.
#define IS_IPHONE_5 ([UIScreen mainScreen].bounds.size.height == 568)
#define IS_IPHONE_6 ([UIScreen mainScreen].bounds.size.height == 667)
#define IS_IPHONE_6_PLUS ([UIScreen mainScreen].bounds.size.height == 736)
will work just as good (or just as bad). Most likely they will work just as bad.
If you are interested in features of the iPhone 6 or 6+, check for the features, not the screen size. It is quite likely that Apple will soon have a 4" phone with all the iPhone 6 features. Or a cheap 6c with a big screen but without iPhone 6 features.
For user interface and so on, just take the mainScreen bounds and lay out your views accordingly. At this point, hard coding for fixed sizes is absolutely ridiculous and will bite you. You should be able to run for example on a 12" iPad with a split screen without problems, and heavens knows what screen size that will be.
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
}