2016-12-06 10 views
0

マイアプリは以下の画像のように、唯一のポートレートモードがあります。 Device OrientationのiOS:特定のランドスケープモード

しかし、それは、カスタマイズのUIViewControllerに風景モードをサポートする必要があります。私はオーバーライドフォロー機能を持っています。

- (BOOL)shouldAutorotate 
    { 
     return NO; 
    } 

    - (UIInterfaceOrientationMask)supportedInterfaceOrientations 
    { 
     return UIInterfaceOrientationMaskLandscape; 
    } 

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
    { 
     return UIInterfaceOrientationLandscapeRight; 
    } 

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

それはほとんどの場合で働いていたが、何とかそれはフォローの画像のように行動します: problem picture

をデバイスの向きとMyViewControllerの向きの間で競合しているがあるようです。

PS:私のデバイスはiPhone 6s Plusで、システムはiOS 10.0です。この問題はiPhone 6sにも存在します。

+0

私はあなたにこれを達成するための代替案を提案できますか? – KKRocks

+0

はい、plz、私が知りたい、thx – zxbeef

+0

私の答えをチェックしてください。私のプロジェクトでうまくいきました。 – KKRocks

答えて

0

以下を参照してくださいには、これを試してみてください。

AppDelegate.h

@property() BOOL restrictRotation; 

AppDelegate.m

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
if(self.restrictRotation) 
    return UIInterfaceOrientationMaskPortrait; 
else 
    return UIInterfaceOrientationMaskAll; // you can change orientation for specific type . for ex landscape left 
} 

のViewController

-(void) restrictRotation:(BOOL) restriction 
{ 
    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; 
    appDelegate.restrictRotation = restriction; 
} 

のviewDidLoad

[self restrictRotation:YES]; or NO 

はあなたがより多くのために

を変更する必要があり、すべてのViewControllerにこの行を記述する必要があります:あなたはAppDelegate .Thisに次のコードを使用することができますhttps://stackoverflow.com/a/25952571/3901620

+0

私のプロジェクトは他の開発者が静的ライブラリとして使用するように設計されているため、AppDelegateを変更することは適切でない可能性があります。 Thxはすべて同じです。 – zxbeef

+0

ほとんどの場合、私のコードはうまく動作しますが、MyViewControllerは偶然回転しません。そして、私は理由を知らない... – zxbeef

0

こと はスウィフトコード動作する唯一の可能な解決策である

func application(_ application: UIApplication, 
supportedInterfaceOrientationsFor window: UIWindow?) -> 
UIInterfaceOrientationMask { 

     let vc = self.window?.currentViewController() 
     if vc?.isKind(of: YourDesiredVCToChangeOrientation.self) == true { 
      return UIInterfaceOrientationMask.landscape; 
     } else { 
      return UIInterfaceOrientationMask.all ; 
     } 

    } 
関連する問題