2012-07-21 77 views
6

在Android中,您可以使用碎片來開發僅針對手機和表格的一個應用程序,因此您可以擁有不同的用戶界面。您甚至可以只使用佈局,並在代碼上運行平板電腦或電話邏輯。iOS等效於Android碎片/佈局

我需要爲iPhone和iPad開發一個應用程序,我不知道是否有類似的實現不同的用戶界面和輕微不同的行爲。在我的情況下,iPhone應用程序會使用屏幕底部的標籤,但iPad應該使用左側的菜單。

回答

2

是的,你可以爲iPhone和iPad使用不同的UI。 創建兩個XIB文件,並顯示他們在屏幕上使用時,這種情況下啓動XIB

UIViewController *viewController; 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; 
} else { 
    viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; 
} 
[self.navigationController pushViewController:viewController animated:YES]; 
+0

我想用這種技術,我可以照顧控制器上的邏輯上的小差異,對吧? 我想避免重複代碼,但有時會有不同的行爲。 – momo 2012-07-21 12:32:23

+0

@momo這是我也這樣做的方式。 – huesforalice 2012-08-13 14:13:23