代码之家  ›  专栏  ›  技术社区  ›  balexandre

如何用iPhone和iPad两种产品启动项目?

  •  2
  • balexandre  · 技术社区  · 15 年前

    使用预发布的xcode 3.2.3,我将其作为一个启动项目获得。

    alt text http://www.balexandre.com/temp/2010-04-17_1155.png

    我该如何选择/做才能使一个既能以ipad又能以iphone为目标的项目变得伟大呢?( 不在iPad上显示iPhone应用程序 但是一个真正的iPad视图?

    谢谢您。


    为了避免问题:

    • iPhone OS 3.1.3 是iPhone的最新版本吗
    • iPhone OS 3.2 是iPad的最新版本吗

    我的问题 不违反我和苹果必须遵守的任何协议 因为我的问题是关于那些已经公开发行的。

    我刚刚说过,在我的操作系统中,我运行的是Xcode3.2.3,仅此而已。

    2 回复  |  直到 14 年前
        1
  •  11
  •   balexandre    15 年前

    找到了一个简单的方法:

    alt text http://www.balexandre.com/temp/2010-04-17_1242.png

    alt text http://www.balexandre.com/temp/2010-04-17_1241.png

    然后,如果您想切换到每个设备的XIB文件,比如说,iPhone的主视图是A,iPad的主视图是B,在您的AppDelegate中,您添加了:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
        // The default have the line below, let us comment it
        //MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
    
        // Our main controller
        MainViewController *aController = nil;
    
        // Is this OS 3.2.0+ ?
        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                // It's an iPad, let's set the MainView to our MainView-iPad
            aController = [[MainViewController alloc] 
                                  initWithNibName:@"MainView-iPad" bundle:nil];
        else 
                // This is a 3.2.0+ but not an iPad (for future, when iPhone runs with same OS than iPad)
            aController = [[MainViewController alloc] 
                                  initWithNibName:@"MainView" bundle:nil];
    
        #else
            // It's an iPhone (OS < 3.2.0)
            aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
        #endif
    
        // Let's continue our default code 
        self.mainViewController = aController;
        [aController release];
    
        mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
        [window addSubview:[mainViewController view]];
        [window makeKeyAndVisible];
    
        return YES;
    }
    
        2
  •  0
  •   Akshay    14 年前

    您可以选择“通用”应用程序类型。