2012-10-22 49 views
0

如果設備是iPhone 5,需要啓動特定故事板,如果設備是iPhone 4S或更舊版本,則需要啓動另一個。我知道,我需要添加一些代碼做didFinishLaunchingWithOptions方法,但我不知道哪一個!啓動特定Storybaord

任何人都可以給我正確的代碼?

回答

0

你必須定義兩個不同的故事板。一個用於iPhone 4尺寸,一個用於iPhone 5尺寸。

然後將下面的代碼添加到您的應用程序代理應用程序didFinishLaunchingWithOptions方法...

// Override point for customization after application launch. 
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; 

if (iOSDeviceScreenSize.height == 480) 
{ 
    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35 
    UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"iPhone4" bundle:nil]; 

    // Instantiate the initial view controller object from the storyboard 
    UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController]; 

    // Instantiate a UIWindow object and initialize it with the screen size of the iOS device 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // Set the initial view controller to be the root view controller of the window object 
    self.window.rootViewController = initialViewController; 

    // Set the window object to be the key window and show it 
    [self.window makeKeyAndVisible]; 
} 

if (iOSDeviceScreenSize.height == 568) 
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen 
    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4 
    UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"iPhone5" bundle:nil]; 

    UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController]; 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window.rootViewController = initialViewController; 
    [self.window makeKeyAndVisible]; 
} 
return YES; 

或者你可以總是試圖用自動佈局你的運氣。無論哪種方式工作。

0

您可以檢查爲iPhone 4/iPhone 5和實例根據它

下面的代碼情節串連圖板,甚至會告訴你iPhone或iPad。

可以在全球範圍內通過應用程序保存iPhone或iPad布爾。

注意:默認情況下iphone4 storyboard將被實例化。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 


iPhone5 = NO; 
iPad = NO; 

// Override point for customization after application launch. 
UIStoryboard *storyBoard; 

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
{ 
    if ([UIScreen mainScreen].scale == 2.0f) 
    { 
     CGSize result = [[UIScreen mainScreen] bounds].size; 
     CGFloat scale = [UIScreen mainScreen].scale; 
     result = CGSizeMake(result.width * scale, result.height * scale); 

     if(result.height == 960) 
     { 
      iPhone5 = NO; 
      // NSLog(@"iPhone 4, 4s Retina Resolution"); 
     } 
     if(result.height == 1136) 
     { 
      iPhone5 = YES; 
      // NSLog(@"iPhone 5 Resolution"); 
      storyBoard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; 
      UIViewController *tabBarController = [storyBoard instantiateInitialViewController]; 
      self.window.rootViewController = tabBarController ; 
     } 
    } 
    else 
    { 
     // NSLog(@"iPhone Standard Resolution"); 
     iPad = YES; 
    } 
} 
else 
{ 
    iPad = YES; 
} 

return YES; 

}