2013-11-23 65 views
4

我創建了一個「單一視圖應用程序」項目並將所有選項設置爲啓動並僅支持橫向。但該應用程序以縱向方向啓動窗口。如何使通用Xcode 5應用項目在橫向方向上啓動?

控制檯輸出說application:didFinishLaunchingWithOptions:之後的窗口是:

{{0, 0}, {768, 1024}} 

我增加了一個標準的系統按鈕來查看視圖控制器來說明該應用程序是橫向和縱向沒有,但該窗口是肖像。

由於堆棧溢出白色背景彩色我在Photoshop中右側的灰色,所以你可以看到它:

enter image description here

application:didFinishLaunchingWithOptions:我彩色的窗口紅色。這顯然不是在橫向方向。

我已經嘗試了所有的招數,我知道:

1)的Info.plist包含UISupportedInterfaceOrientations鍵搭配: UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight

2)的Info.plist包含UISupportedInterfaceOrientations〜ipad的關鍵有: UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight

3)Info.plist包含初始界面方向的UIInterfaceOrientation鍵: UIIn terfaceOrientationLandscapeRight

4)點擊了Xcode中的項目,然後選中所有人像選項,只檢查了景觀選項:

enter image description here

5)AppDelegate中和ViewController中都有:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 

- (BOOL)shouldAutorotate { 
    return YES; 
} 

6)AppDelegate有:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 

Xcode創建了兩個故事板文件。我現在只在iPad上測試。一個是Main_iPad.storyboard,它顯示了一個縱向的視圖控制器。但它只是一個模擬的接口指標。改變爲風景,並如預期沒有效果。

enter image description here

在應用程序啓動我檢查UIScreen界限,它也顯然是縱向,而不是橫向:

CGRect screenBounds = [[UIScreen mainScreen] bounds]; // {{0, 0}, {768, 1024}} 

我怎樣才能使它在景觀推出,開創橫向窗口?

回答

1

我以前有類似的問題,所以也許他們有關...

我有一個問題,因爲我在我的視圖控制器的initWithNibName:bundle:中以編程方式創建了我的視圖,並且出於某種原因,這樣做會使新視圖以縱向模式定向,而其他應用程序正在運行橫向。

我發現了這個問題的兩個修復程序。 1)使用你的故事板,而不是編程方式創建視圖或2)移動代碼來創建從您的視圖控制器的initWithNibName:bundle:法的觀點,並將其放置在視圖控制器的-viewDidLoad:方法是這樣的:

-(void)viewDidLoad { 
    //Create your view programmatically 
    UIView *view = [[UIView alloc] initWithFrame:self.view.frame]; 
    //Customize view 
    [self.view addSubview:view]; 
} 

這是解決辦法對於我有類似的問題。雖然我認識到我們程序員有很多方法可以使事情不能以正確的方式工作,但我希望這是答案!

0

雖然在視圖控制器,那麼接口生成器中單擊在尺寸檢查開關模擬尺寸自由形式(從固定),進入1024 寬度和768 高度。這個對我有用。

相關問題