0

ルートコントローラがUINavigationControllerであるアプリがあります。 1つのボタンを押すと、別のView Controllerがプッシュされます。まだ別のものを押すと、オーバーレイでAVCaptureSessionが開始されます。私はそのビューを望んでおり、そのビューは横長で、縦長ではないことが唯一のものです。私は数多くのチュートリアルを見てきましたが、何も動いていません。iOSとNavigationControllerをルートメイクの1つのコントローラのみで表示

私が得ている最も近いです:viewDidAppearで

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; 
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 

。しかし、いくつかの問題があります。 1つ目は直ちにポートレートに戻ります。 2つは、他のビューはまだすべてのポートレートと風景にすることができ、私はそれを望んでいない。私は助けが必要です。私のアプリデリゲートで

答えて

0

、私はこのコードを使用してのみ、ポートレートモードが選択されていることを確認します

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    if ([self.window.rootViewController.presentedViewController isKindOfClass:[SecondViewController class]]) 
    { 
     SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController; 

     if (secondController.isPresented) 
     { 
      return UIInterfaceOrientationMaskLandscape; 
     } 
     else return UIInterfaceOrientationMaskPortrait; 
    } 
    else return UIInterfaceOrientationMaskPortrait; 
} 
0

はい、あなたのappDelegateで怒鳴るの方法を置くことによって、風景のような特定のViewControllerを作ることができます。

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
if(self.restrictRotation) 
    return UIInterfaceOrientationMaskPortrait; 
else 
    return UIInterfaceOrientationMaskAll; 
} 

、あなたのappDelegateに

@property (nonatomic) BOOL restrictRotation; 

を1つのブール値プロパティを取ると、あなたが方向を変更したいビューコントローラにappDelegateインスタンスを共有し、制限が怒鳴るの方法のように

-(void) restrictRotation:(BOOL) restriction 
{ 
    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; 
    appDelegate.restrictRotation = restriction; 
} 
を変更することができるように作成します

は、ビューコントローラからこのメソッドを呼び出して、向きを変更します。

[self restrictRotation:NO]; 

    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; 
[[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 

と最も重要なことは、あなたのビューは、そうでない場合も、ランドスケープモードでなる他のすべてのViewControllerを消えることになるとき肖像画に向きを変更することです。

-(void)viewWillDisappear:(BOOL)animated 
{ 
    NSNumber *value = [NSNumber  numberWithInt:UIDeviceOrientationPortrait]; 
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 
    [self restrictRotation:YES]; 
} 

私はこれがあなたに役立つことを望みます。

関連する問題