2012-12-26 39 views
0

我正在製作iphone應用程序。但在未來,這款應用也應該可用於iPad。目前我正在使用故事板,因爲通過這種方式可以使它成爲iPad。iPad和iPhone的不同佈局

我的問題是現在,一些意見像一個長輪廓形式,你把它放在一個滾動視圖。但是你不能在故事板中創建滾動視圖佈局,所以我使用代碼創建了它們。但是,如果我希望此視圖佈局也可用於iPad,我該怎麼做?

我應該重寫iPad的佈局代碼,然後做一些設備檢測? 最佳做法是什麼?

+2

備註:我更喜歡使用UITableViewController註冊/登錄/ profile /等,因爲它需要的代碼較少。 UITableViews真的很強大,並且不需要任何iPhone到iPad適配的工作。但那是我個人的選擇! – rdurand

回答

2

我認爲更好地檢測硬件並編寫不同的佈局代碼。
您可以使用蘋果的宏:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    // Write your layout code for iPad there 
} 
else 
{ 
    // Write your layout code for iPhone/iPod there 
} 
0

下面將會對您有用。

#define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"]) 
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) 
#define IS_IPAD ([[[UIDevice currentDevice] model] isEqualToString:@"iPad"]) 
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f 
#define IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f 


if(IS_IPHONE_5_SCREEN) 
{ 
    if(IS_IPHONE) 
     NSLog(@"Hey, this is an iPhone 5 screen!"); 
    else if(IS_IPOD) 
     NSLog(@"Hey, this is an iPod 5 screen!"); 
    else 
     NSLog(@"Hey, this is a simulator screen with iPhone 5 screen height!"); 
} 
else if(IS_IPHONE_4_SCREEN) 
{ 
    if(IS_IPHONE) 
     NSLog(@"Hey, this is a lower iPhone screen than 5!"); 
    else if(IS_IPOD) 
     NSLog(@"Hey, this is a lower iPod screen than 5!"); 
    else 
     NSLog(@"Hey, this is a lower simulator screen than 5!"); 
} 
else if(IS_IPAD){ 
    NSLog(@"Hey, this is an iPad screen!"); 
} 
else{ 
    NSLog(@"Hey, this is an ipad simulator screen!"); 
} 

乾杯!

0

該解決方案相當簡單。 首先,我認爲你不能在故事板內創建滾動視圖。但這是可能的! 您可以通過here找到如何操作。

所以現在的解決方案是,您可以專門爲iPad創建另一個故事板!