0

私のアプリケーションでは、ビューを管理するためにナビゲーション コントローラーを使用しています。私のログインページは、縦向きと横向きの両方のビューをサポートしています。ユーザーがログインすると、2 番目のビューがホームになり、ランドスケープ モードのみがサポートされます。私がやりたいことは、縦向きのホームページを使用してホームにログインしたユーザーが、デバイスが縦向きであっても横向きに表示されることです。

だから私がしたことは、次のようにホームページのviewWillAppear方法でステータスバーの向きを横向きに変更することでした。

    -(void)viewWillAppear:(BOOL)animated{

        [super viewWillAppear:animated];
        [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRight animated:NO];
UIDeviceOrientation orien = [[UIDevice currentDevice] orientation];
    }

shouldAutorotateToInterfaceOrientationまた、次のようにオーバーライドしました

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

return YES;

}

私の問題は、ステータスバーが横向きに変更されても、私のUIViewController(家)が横向きのままであることです。デバッグ中に、ステータスバーの向きを横向きに変更しても[[UIDevice currentDevice] orientation]縦向きに戻ることがわかりました。私は一日中インターネットを使っていました。そして、他の人が提供する多くのソリューションを実装しましたが、私の一日は無駄になりました. これらの問題を解決するために私を導くことができますか?

4

3 に答える 3

1

あなたはただ好きになる必要があります:-

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {


        return YES;
    }
    else
    {
        return NO;
    }
}

ランドスケープのみを開きたい特定のクラスについて

iOS6:-

-

(BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskLandscape;
}
于 2013-03-18T12:53:13.037 に答える
0

Appleは、デバイスの向きを強制することを望んでいません。しかし、トリックがあります。残念ながら、私は自分のコードにアクセスできません。

1. Your app in general supports all orientations. 
2. All view controllers only return their supported interface orientation in their overwrites respectivly (in supportedInterfaceOrientations). 
3. All view controllers return YES in shouldAutorotateToInterfaceOrientation only for their supported orientations. 

それは結構です。ただし、それでもユーザーは実際にデバイスを回転させる必要があります。そうしないと、方向変更メカニズム全体が呼び出されません。ここで、方向を強制的に変更する場合は、次のようにします。

4. Use setStatusBarOrientation to set the orientation before the next view controller is displayed. 
That alone would not do anything. Plus it would not take any effect if the next view controller is pushed. It would work fine only when the next view controller is presented modally. 
5a. So if you want to present the rotated view controller modally, then do it. 
5b. If you still need to push it then: 
5b1. Create an empty UIViewController instance. alloc/init will do. 
5b2. Present it modally
5b3. Dismiss it modally 
Now, the new view controller was not even visible to the user but the device - here comes the magic - is rotated now.  
5c4. Next push the view controller that you want to display roated. 

帰りはその逆です:)

タブバーを使用すると、上記のすべてがより複雑になります。タブバーを使用していますか?回転メソッドを上書きするためにサブクラス化する必要のあるタブバーを使用して、それを機能させることができました。タブバーのないアプリでは、UIApplication(!)をサブクラス化しましたが、本当に必要だったのか、都合の悪いときに(50以上のビューコントローラーに変更を加える代わりに)行ったのかを思い出しません。しかし、原則として、上記はトリックを行うものです。

PS:コードサンプルと一緒にここでより詳細な答えを見つけます: ランドスケープモードでのナビゲーションコントローラーの提示はiOS6.0で機能していません

于 2013-03-18T13:05:32.307 に答える
0

あなたはで試すことができます

- (NSUInteger)supportedInterfaceOrientations {
      return UIInterfaceOrientationMaskPortrait;
  }

- (BOOL)shouldAutorotateToInterfaceOrientation:     (UIInterfaceOrientation)toInterfaceOrientation {
     return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
 }

または、プッシュするのではなく、モーダルとして提示してみてください。

于 2013-03-18T12:56:16.713 に答える