2012-10-03 67 views
0

我試圖讓我的xib文件之一旋轉到肖像,就好像它是默認的第一個地方。如何使我的界面方向自動旋轉爲縱向?

我讓我的應用程序只支持風景方向。在plist中,我設置了「初始界面方向爲橫向(右側主頁按鈕)」,因爲大多數應用程序都是在橫向模式下運行的。

我在實現文件放置的代碼是:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 

return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight; 

}

現在改變到需要的界面處於縱向模式視圖控制器時,我已經把在廈門國際銀行驗證碼文件的實現文件,以使其進入縱向模式並單獨支持縱向模式。因此,即使設備處於橫向模式,它仍會以縱向模式運行視圖。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 

return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortrait; 

}

儘管這似乎並沒有工作。它只是保持在橫向模式下,擠壓了我放在xib文件中的圖像視圖和其他對象。我如何讓xib旋轉到肖像模式?謝謝。

+0

iOS 6已經添加了3種新的方法來方便界面旋轉,請檢查它們:http://stackoverflow.com/questions/12404556/interface-orientation-in -ios-6-0 –

+0

哪個iOS版本和你如何改變viewController? – jcesarmobile

+0

您使用哪種方法來獲取您的視圖.. pushviewcontroller或presentModalViewController – Rajneesh071

回答

0

嘗試這些鏈接(link1link2)如果可以幫助你。

0
change your Xib in Landscape Mode only and then click on your project file then target then select only Landscape mode or Portrait Mode(left/right or both) 
    then go to this method 
I am using Landscape Mode. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

enter image description here

0

我的經驗顯示,在plist文件設置UIInterfaceOrientation沒有任何效果。在另一方面,你可以通過設置強制在啓動時的方向(例如橫向):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft]; 
    // your stuff 
{ 

您可以使用此方法也稍後迫使設備的邏輯方向。注意:這是蘋果公司的一種「官方」方法,截止到this document

相關問題