2016-03-22 14 views
1

iPhoneとiPadで単一のViewControllerをロックしたいと思います。 以下のコードは、iPhone 4,5,6 iPad、iPad 2、iPadの網膜で完璧に動作しています。 しかし、iPadのプロで働いていない。iPad Proで動作しない単一のUIViewControllerで自動回転を無効にする

@implementation UINavigationController (Orientation) 
-(NSUInteger)supportedInterfaceOrientations 
{ 
     return [self.topViewController supportedInterfaceOrientations]; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
@end 

上記のコードは、私のビューコントローラに書き込まれていますが、コントローラは表示しません。

+0

iPad版のiOSバージョン – Chetan

+0

カテゴリを使用してメソッドをオーバーライドしようとしないでください。これは未定義の動作です。 – rmaddy

+0

@Chetan iOS 9.1 –

答えて

2

書き込みを、回転しますplistファイル enter image description here

+0

ありがとうございます!私はすべてを試したと思った。プロジェクト情報に適切なチェックボックスを設定し、フルスクリーンでチェックし、適切なメソッドをオーバーライドします。彼らも呼ばれていました。私はinfo.plistに行き、iPadの向きを取り除くことで問題を解決しました。愚かなことに、普遍的なプロジェクトのプロジェクト情報には表示されません。 – VaporwareWolf

+0

@VaporwareWolf Great !!!私の答えがあなたに助けてくれたら、私の答えをアップアップする –

1

はあなたがこれは任意の回転を防止します

を回転させたくない、あなたのビューコントローラでこれを書きます。

回転させたくないView Controllerクラスには、これが必要です。

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

The containing navigation controller class should have this. 

- (BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutoRotate]; 
} 

これが唯一の肖像画にuはポートレートモードで

@implementation UINavigationController (Orientation) 
-(NSUInteger)supportedInterfaceOrientations 
{ 
     return [self.topViewController supportedInterfaceOrientations]; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
@end 

#pragma mark Orientation 
-(BOOL)shouldAutorotate 
{ 
    [super shouldAutorotate]; 
    return NO; 
} 
-(NSUInteger) supportedInterfaceOrientations { 
    [super supportedInterfaceOrientations]; 
    // Return a bitmask of supported orientations. If you need more, 
    // use bitwise or (see the commented return). 
    return UIInterfaceOrientationMaskPortrait; 
    // return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation { 
    [super preferredInterfaceOrientationForPresentation]; 
    // Return the orientation you'd prefer - this is what it launches to. The 
    // user can still rotate. You don't have to implement this method, in which 
    // case it launches in the current orientation 
    return UIInterfaceOrientationPortrait; 
} 

をロックそして今、以下これを実行するコントローラを表示ビューコントローラでは、このコードの下

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 
+0

この解決策は機能しません。 –

+0

編集をチェックして同じものを試してください – Chetan

+0

View Controllerで両方のメソッドを宣言しないでください。 1つはビューコントローラで宣言され、もう1つはナビゲーションコントローラクラスで宣言されます。もう一度答えを読む – Chetan

関連する問題