2012-09-21 169 views
0

我使用此代碼來適應我的故事板根據設備(iPhone 5或更少):iPhone 5的屏幕適應

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iphone5 storyboard" bundle:[NSBundle mainBundle]]; 

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){ 
    if(UIScreenOverscanCompensationScale==1136/640){ 
     //move to your iphone5 storyboard 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iphone5 storyboard" bundle:[NSBundle mainBundle]]; 
    } 
    else{ 
     //move to your iphone4s storyboard 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; 
    }} 

的代碼不能使用,即使我只是工作的地方

...它仍然加載iPhone正常。

我把它放在:

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

在應用程序委託。這是正確的嗎??在應用設置中,我選擇故事情節

+1

目標上的摘要頁的故事板可能設置爲MainStoryboard_iPhone –

回答

0

我設法解決它通過這種方式:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){ 
    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0){ 
     //move to your iphone5 storyboard 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iphone5 storyboard" bundle:[NSBundle mainBundle]]; 
     UIViewController *vc =[storyboard instantiateInitialViewController]; 

     // Set root view controller and make windows visible 
     self.window.rootViewController = vc; 
     [self.window makeKeyAndVisible]; 
    } 
    else{ 
     //move to your iphone4s storyboard 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; 
     UIViewController *vc =[storyboard instantiateInitialViewController]; 

     // Set root view controller and make windows visible 
     self.window.rootViewController = vc; 
     [self.window makeKeyAndVisible]; 
    }} 
+0

我在哪裏放這個代碼?的appDelegate? –

0

原來iphone的問題是:

UIScreenOverscanCompensationScale==1136/640 

永遠不會爲真。

檢查UIScreenOverscanCompensationScale正在做什麼並返回一個BOOL。

+0

肯定的,但代碼不叫在所有 – Alessandro

0

是否MainStoryboard仍在目標摘要下指定?我相信這將是應用程序首先看的地方。

+0

好了,我已經決定在storyboard下的故事板=>主要故事板。因爲我必須決定一個故事板。 – Alessandro