2012-04-13 76 views
1

我正在製作一個通用應用程序,我想知道是否可以將初始方向設置爲適用於iPad的橫向和適用於iPhone的縱向?目前,我在info.plist文件中設置了initial interface orientation,但它似乎沒有針對iPad和iPhone的不同選項。如果它不能通過info.plist文件完成,那麼如何以編程方式做到這一點?iPad和iPhone的不同推出方向?

+0

http://stackoverflow.com/a/17628668/468724 – 2013-07-13 09:07:55

回答

1

看起來與supported orientation S中initial interface orientation屬性衝突。不過,我找到了解決方案here

1

編程,你可以做以下使用的代碼 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 

     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
      return YES; 
     } 

    } 
    else { 

     if (interfaceOrientation == UIInterfaceOrientationPortrait) { 
      return YES; 
     } 
    } 

return NO; 

}

+0

我在這裏找到了解決方案:http://stackoverflow.com/questions/402/iphone-app-in-landscape-mode – tipycalFlow 2012-04-13 12:07:50

+0

這不是解決方案我一直在尋找,我的朋友......問題在於啓動方向(當iOS尚未開始使用方向通知時,所以'shouldAutorotateToInterfaceOrientation'不會被**調用)。如果你在你的appdelegate中'NSLog'設備的方向,你會得到'orientation unknown'的輸出! – tipycalFlow 2012-04-19 05:15:31

0
UIDevice* thisDevice = [UIDevice currentDevice]; 
    if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) 
    { 
     [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight]; 
    } 
    else 
    { 
     [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 
    } 
+0

'setOrientation'可以讓我的應用程序被拒絕。不管怎麼說,還是要謝謝你 – tipycalFlow 2012-04-13 12:05:45