2011-03-14 80 views

回答

5

只需檢查視圖控制器的自動調整大小的屬性。

(固定語法錯誤)

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

    return NO; 
} 
10

如果你想只需在應用程序的Info.plist文件停止整個應用程序旋轉再改支持的接口方向初始界面取向財產爲縱向或橫向依賴on你

+0

這很容易和有用。有沒有辦法在一個視圖控制器中覆蓋它?我有10個視圖控制器,其中一個需要在橫向上,但其餘的我用這種方法只限於縱向。 – PeonProgrammer 2015-02-27 18:13:06

+0

如果是這種情況,您必須重寫方法 - (NSUInteger)supportedInterfaceOrientations { return __orientation; }在所有視圖中控制器 – iOSPawan 2015-03-10 03:55:05

-3

我強烈建議不要在iPad上停止旋轉,因爲支持旋轉是iPad上必須的。這是因爲iPad不像通常以縱向視圖(AKA Vertical)保存的iPhone那樣採用正常的方式。因此,您必須將選擇留給用戶以最終鎖定方向

HIG實際上並未將此作爲要求聲明,但作爲建議,但有許多應用程序被此問題拒絕。

通過,如果你想這對於限制數視圖控制器應實現方式:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if(interfaceOrientation == UIInterfaceOrientationPortrait){ 
     return YES; 
    } 
} 
5

在iOS6的shouldAutorotateToInterfaceOrientation已被棄用。改爲覆蓋supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation

Please see

+0

您的[請參閱](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixApresentedApirecatedAPI.html#//apple_ref/occ/instm/ UIViewController/shouldAutorotateToInterfaceOrientation%3a)鏈接不再有效 – dumbledad 2016-02-22 11:54:37

0

全球可控旋轉鎖定的主要思想是寫包含鎖定機構對每個視圖控制器的UIViewController類別。

你只需要修改supportedInterfaceOrientations方法進行了全局

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return __orientation; 
} 

這裏__orientation是可以通過類的方法來設置靜態變量。

完全實現的類別呈現here

0

請更新您的projectname.plist這樣。支持的接口方向只有一個對象「肖像(下home鍵)」

1

在我的項目的info.plist我已經刪除了在iPad上Supported interface orientations像下面的圖片的一些關鍵(我只給出了縱向支持)

enter image description here