2012-09-27 43 views
3

嗨,我正在檢查iOS6的方向變化,我做了一切工作正常,除了一件事情。無法在橫向上啓動應用程序。如何將開始方向設置爲橫向?

如何才能在景觀上啓動應用程序?我發現這How to force a UIViewController to Portrait orientation in iOS 6,但這不工作,應用程序總是開始在肖像,我需要開始在景觀...

當我去其他視圖,然後回到「初始視圖」它是景觀!但當應用程序啓動時,它的肖像...

謝謝!

----------------------------- UPDATE ---------------- ---------------

這是我如何從應用程序的委託加載主視圖:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
myViewController = [[myViewController alloc] init]; 

self.navController = [[UINavigationController alloc] initWithRootViewController:myViewController] ; 

[self.window setRootViewController:navController]; 
[self.window makeKeyAndVisible]; 

--------- -------------------- UPDATE 2 ---------------------------- - 我做它的工作,我改變了以往代碼:

self.navController = [[UINavigationController alloc] init] ; 
[self.window setRootViewController:navController]; 
[self.window makeKeyAndVisible]; 
[navController presentViewController:myViewController animated:NO completion:NULL]; 

我希望這是對別人有用!

回答

0

這是我如何做它的工作:

self.navController = [[UINavigationController alloc] init] ; 
[self.window setRootViewController:navController]; 
[self.window makeKeyAndVisible]; 
[navController presentViewController:myViewController animated:NO completion:NULL]; 

我希望它可以幫助別人!

0

你試過嗎?

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES]; 

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES]; 

這兩個的iOS 6和iOS 5

我有試圖旋轉屏幕比我意識到我做的錯誤的另一個問題爲我工作嘗試加載新的屏幕:

[self.navigationController presentModalViewController:controller animated:YES]; 

代替:

[self.navigationController pushViewController:controller animated:YES]; 

第二個工作,但第一個沒有做我所期望的。

+0

感謝提示,但我沒有在我的應用程序中使用這些行......這讓我發瘋...... – Andres

+0

嘗試第一行代碼。在我的情況下,我在我的應用程序中使用'setStatusBarOrientation:UIInterfaceOrientationLandscapeRight',因爲當視頻(在全屏幕上播放並且可以旋轉)在橫向模式下完成時,我必須強制視圖保持縱向。 – jMelnik

+0

對我無用......這讓我很瘋狂,因爲我的應用程序加載了一個視圖,該視圖不在橫向(我需要它是橫向),加載後立即調用另一個視圖,當我回到橫向的第一個視圖,但它不開始景觀...真的很奇怪...我的想法... – Andres

-1

我一直在摔跤這個太 - 這是怎麼了,我已經修復它:

在viewDidLoad中:

CGRect frame = self.view.bounds; 

if (frame.size.height > frame.size.width) { 
    //hack to force landscape 
    CGFloat holdHeight = frame.size.height; 
    frame.size.height = frame.size.width; 
    frame.size.width = holdHeight; 
    self.view.bounds = frame; 
} 

但我更喜歡一個更好的辦法。

相關問題