【问题标题】:how make app work on iPhone 6 with existing code如何使用现有代码使应用程序在 iPhone 6 上运行
【发布时间】:2014-10-04 02:40:27
【问题描述】:

此代码在我的应用程序委托中.....

@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"];
    }

}

【问题讨论】:

  • 您应该转储所有屏幕检查并为所有设备使用一个可调整大小的故事板。
  • 我将如何继续这样做。任何教程以及我将如何为不同大小的故事板分离代码。是否全部都使用相同的像素定位并调整其大小。

标签: ios objective-c iphone-6 iphone-6-plus


【解决方案1】:

将此代码粘贴到您的 AppDelegate.m 中

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:(v) options:NSNumericSearch] != NSOrderedAscending)

应用程序didFinishLaunchingWithOptions中的以下代码:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")){
     mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil]; }

【讨论】:

  • 感谢您的建议,但最终当我更新 Xcode 时,我的视图控制器上的自动布局已打开,这就是我的游戏表现怪异的原因。关闭它后,一切似乎都可以在 iPhone 6 和 6 plus 的模拟器中运行。
猜你喜欢
  • 2012-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-04
  • 1970-01-01
相关资源
最近更新 更多