2011-12-21 13 views
2

私は、1つのタブがポートレートモードとランドスケープモードの両方で利用可能なタブベースのアプリケーションを持っています。オリエンテーションを強制的に変更する

私は、shouldAutorotateToInterfaceOrientationで回転を許可するかどうかをチェックしていますが、私がランドスケープモードになっているときに別のタブを選択すると、そのビューコントローラをロードする必要があります。レイアウトモード。

私はステータスバーの向きを設定しようとしましたが、移動する唯一の視覚的な要素はステータスバーでした。

ヒントや例があれば、大変感謝しています。

答えて

7

私はこれを行うことができましたが、私は今あなたに警告しています、それはハックです。

まず、私はUITabBarControllerのカテゴリを作成したが UITabBarController+SelectiveRotationと呼ばれる:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; 
} 

これは、選択したタブが方向性を可能にするたびにTabBarには、自由に回転することができます。 UITabBarController(おそらくあなたのアプリケーションデリゲートにあります)を作成しているところで、このファイルをインポートしてください。

はその後、私は私のAppDelegate自体タブバーのデリゲート作ってもらいました、と私は、このメソッドを実装し:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { 
    // this ensures that the view that will be shown is presented in a supportred rotation 
    UIViewController *c = [[UIViewController alloc]init]; 
    [viewController presentModalViewController:c animated:NO]; 
    [viewController dismissModalViewControllerAnimated:NO]; 
    [c release]; 
    if ([UIViewController respondsToSelector:@selector(attemptRotationToDeviceOrientation)]) { 
     // this ensures that the view will be presented in the orientation of the device 
     // This method is only supported on iOS 5.0. iOS 4.3 users may get a little dizzy. 
     [UIViewController attemptRotationToDeviceOrientation]; 
    } 
} 

このコードの第2ビットは、いつタブ許容可能な方向に回転させるようにタブバーを強制的に変更。たとえば、回転可能なタブに移動して横向きに移動し、縦向きのみをサポートするタブに移動すると、縦向きの変更が強制的に適用されます。 iOS 4.3以前では、回転タブに戻ると、回転したタブに戻って、それを放置した向きで表示されます。その周りに道を見つけることができませんでした。

クライアントの要件であるため、私はこれをすべて行いましたが、これは実際には非常に有用な設計ではないと思います。私は方向を間違えるような視覚的調整をあまり多く見出すことはできませんが、デバイスをこの方法で強制的に回転させることは、瞬間的であるため非常に厄介です。あなたはそれを試して、あなたがそれについてどのように感じているのかを見たいかもしれません。

+0

また、このメソッドは、UIMoviePlayerControllerの 'によって引き起こさ(のUIWebViewがフルスクリーンビデオの再生を終了し、不要な姿勢の変化を解決し、横にあなたの肖像画のUIViewControllerを強制することができます - (BOOL)setUIOrientation:(int型)の向きをアニメーション:(BOOL)アニメーション強制:(BOOL)強制;) –

+0

私はそのAPIに慣れていないので、ドキュメントで見つけることができません。それはあなたが書いたものですか? –

+1

UIMoviePlayerControllerはビデオを再生するときに 'UIWebView'によって割り当てられます。アプリケーションがポートレートモードのみをサポートしている場合、UIMoviePlayerControllerは向きを強制的に風景に変更することができます。完了]ボタンをクリックします。 p.s.プライベートAPI –

0

次のコードを使用すればうまくいくはずです。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { 
// this ensures that the view that will be shown is presented in a supportred rotation 
UIViewController *c = [[UIViewController alloc]init]; 
[viewController presentModalViewController:c animated:NO]; 
[viewController dismissModalViewControllerAnimated:NO]; 
[c release]; 
if ([UIViewController respondsToSelector:@selector(attemptRotationToDeviceOrientation)]) { 
    // this ensures that the view will be presented in the orientation of the device 
    // This method is only supported on iOS 5.0. iOS 4.3 users may get a little dizzy. 
    [UIViewController attemptRotationToDeviceOrientation]; 
} 

}