2012-11-20 49 views
1

當我在Xcode 4.5上爲iOS 5創建Ipad應用程序時,我遇到了橫向方向問題 我看到很少有相關的問題,但其中大多數與我的情況相反。如何在Xcode 4.5中創建IOS 5.1應用程序

我不'使用任何代碼,如Bool autorotate我只是選擇接口構建器上的風景。使用自動佈局被取消選擇。

當我創建應用程序,我選擇的項目文件夾IOS部署目標5.1(藍色圖標)

enter image description here

生成設置爲架構基礎SDK是IOS 6

enter image description here

在故事板導航控制器設置爲橫向和界面文件設置爲5.1

enter image description here

在IOS 6模擬器景觀效果很好:

enter image description here

但在IOS 5.1模擬器景觀不工作,迷惘

enter image description here

我錯過了什麼?我怎樣才能使這個工作的5.1和6版本?

編輯=====

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) 
     return YES; 

    return NO; 
} 

上面的代碼也不起作用。它仍然是一樣的。

回答

2

您應該重寫shouldAutorotateToInterfaceOrientation:視圖控制器和返回是您想要的方向,例如

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight; 

}

+0

編輯的問題我實際上已經嘗試過在我發佈問題之前仍然無法運行 –

+0

您將受支持的接口方向設置爲橫向,對嗎? – Setrio

+0

在故事板上 - >模擬指標 - >方向設置爲橫向 –

1

IOS 6.0之前,你必須重寫此方法對項目的所有ViewControllers 。在iOS 6中蘋果終於做了正確的這種行爲

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 

}

0

更新所有的視圖控制器用下面的代碼。

工程模擬器5.0及更高版本。

-(NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAll; 
} 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
相關問題