2012-08-27 60 views
0

我不知道爲什麼設備方向不起作用。設備方向

在項目屬性:

enter image description here

在我的代碼有:

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

我探討它在我的iPhone,並不會改變。

有什麼缺失?

預先感謝您

編輯(info.plist中)

enter image description here

+0

支持的界面方向添加info.plist – Rajneesh071

+1

您的設備上是否啓用了方向鎖? –

+0

不,它沒有被鎖定,我也嘗試過在xcode中使用iphone模擬器 – user1256477

回答

0

打開info.plist文件XCode,並添加一行 - 類型的數組Supported interface orientation

點擊它旁邊的加號按鈕,列出所有想要使用的方向。 您可以爲iPhoneiPad設置不同的設置。

+2

如上圖所示選擇支持的方向時,會自動完成此操作。 –

+0

使用此信息編輯我的帖子 – user1256477

0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
if((interfaceOrientation == UIInterfaceOrientationPortrait) || 
    (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| 
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) 
{ 
    return YES; 
} 

return NO; 

} 
+1

這與OP的代碼在語義上相同。 –

+1

好吧,我的錯誤... – NightCoder

0

你的代碼在哪裏是shouldAutorotateToInterfaceOrientation:執行?它應該是UIViewController的每個子類的一種方法。

嘗試通過在shouldAutorotateToInterfaceOrientation:中放入日誌語句或斷點來確保它正在工作。如果沒有被調用,其他地方的視圖控制器正在爲您決定有效的方向。

+0

我試着你說的NSLog,該方法被稱爲,但它不會改變 – user1256477