2011-08-05 86 views
3

在xcode 4中,我無法將屏幕方向鎖定爲僅肖像,即使我只選擇了肖像。如何以編程方式執行此操作?無法將屏幕方向鎖定爲僅限於xcode 4中的肖像?

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

此代碼的工作在一個新的空白項目

+0

請發佈您到目前爲止的代碼。 – PengOne

+0

我想通了 – Omar

回答

6

對於每個視圖控制器(或只是母公司),實現-shouldAutorotateToInterfaceOrientation:設置默認方向爲縱向,然後做:

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

或者,你可以這樣做:

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

這將允許旋轉到門機但不能遠離它。

+1

它似乎堅持我開始項目的設置。我做了一個新的空白應用程序,它的工作原理,但不是在我現有的應用程序!這真的很煩人! – Omar

10

接受的答案也不適用於我。這樣做:

在位於「支持文件」組中的您的應用的屬性文件(YOURAPPNAME-Info.plist)中,有一個名爲「支持的接口方向」的數組。從陣列中移除兩個橫向值,您的應用將以縱向方向鎖定。