このコードは私のアプリデリゲートにあります.....
@implementation AppDelegate
- (UIStoryboard *)grabStoryboard {
UIStoryboard *storyboard;
// detect the height of our screen
int height = [UIScreen mainScreen].bounds.size.height;
if (height == 480) {
storyboard = [UIStoryboard storyboardWithName:@"Main3.5" bundle:nil];
// NSLog(@"Device has a 3.5inch Display.");
} else if (height == 568) {
storyboard = [UIStoryboard storyboardWithName:@"Main4.0" bundle:nil];
// NSLog(@"Device has a 4inch Display.");
}else {
storyboard = [UIStoryboard storyboardWithName:@"Main7.0" bundle:nil];
// NSLog(@"Device is ipad.");
}
return storyboard;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [self grabStoryboard];
// show the storyboard
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
これは、私のアプリが iPhone 6 および 6 plus を除くすべての iOS デバイスで動作する方法です。iPhone 6 および 6 plus を機能させるには、何を追加する必要がありますか。それが役立つ場合。それが役立つ場合、これがビューコントローラーで必要なときにコーディングを分離する方法です。
#define IS_IPAD (( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) ? YES : NO)
#define IS_IPHONE_5 (([UIScreen mainScreen].scale == 2.f && [UIScreen mainScreen].bounds.size.height == 568)?YES:NO)
#define IS_RETINA_DISPLAY_DEVICE (([UIScreen mainScreen].scale == 2.f)?YES:NO)
if (IS_IPAD)
{
//do stuff for iPad
text.text = [NSString stringWithFormat:@"i am an ipad"];
}
else
{
if(IS_IPHONE_5)
{
//do stuff for 4 inch iPhone screen
text.text = [NSString stringWithFormat:@"i am an iphone 5 or 5s"];
}
else
{
//do stuff for 3.5 inch iPhone screen
text.text = [NSString stringWithFormat:@"i am an iphone 4 or lower"];
}
}