2011-08-14 72 views
1

嗨,我剛剛開始iPhone編程。我在Xcode 3.2中爲iPad和iPhone創建了一個通用應用程序,evrerything工作正常。但是現在我想在該應用中實現以下功能:如何:在iPad上自動旋轉和僅在iPhone上縱向顯示?

它應該支持在iPad上自動旋轉,並且只能在iPhone上顯示人像。

我不知道該怎麼做。

我有一個AppDelegate_iPad代表文件, 一個AppDelegate_iPhone代表文件, 和共享選項卡下的ViewController和是這兩個代表份額。

任何想法如何實現該功能。任何幫助,將不勝感激。

感謝 維克

回答

3

在爲要實現這種旋轉行爲期(縣)的視圖控制器(S),做shouldAutorotateToInterfaceOrientation內的檢查,就像這樣:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {  
    UIDevice* thisDevice = [UIDevice currentDevice]; 
    if (thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) 
    { 
     return true; 
    } 
    else 
    { 
     return interfaceOrientation == UIDeviceOrientationPortrait; 
    } 
} 
0

運行iOS 6+的應用程序也將要實施的ViewController的:

- (NSInteger)supportedInterfaceOrientations 

和/或AppDelegate中的:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

例如,

- (NSInteger)supportedInterfaceOrientations 
{ 
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { 
     return UIInterfaceOrientationMaskAll; 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 
相關問題