2011-10-27 22 views
0

私はプログラマチックにタブバーベースのアプリケーションを作成しています。 アプリケーションで:didFinishLaunchingWithOptions(アプリデリゲート)方法Iを入れている:Tab Bar + NavigationControllersアプリで横向きを有効にするにはどうすればよいですか?

self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 

SearchViewController *search_vc = [[[SearchViewController alloc] init] autorelease]; 
SearchBookmarksViewController *search_bookmarks_vc = [[[SearchBookmarksViewController alloc] init] autorelease]; 
ItemsBookmarksViewController *items_bookmarks_vc = [[[ItemsBookmarksViewController alloc] init] autorelease]; 
AboutUsViewController *aboutus_vc = [[[AboutUsViewController alloc] init] autorelease]; 

UINavigationController *search_nav = [[[UINavigationController alloc] initWithRootViewController:search_vc] autorelease]; 
UINavigationController *search_bookmarks_nav = [[[UINavigationController alloc] initWithRootViewController:search_bookmarks_vc] autorelease]; 
UINavigationController *items_bookmarks_nav = [[[UINavigationController alloc] initWithRootViewController:items_bookmarks_vc] autorelease]; 
UINavigationController *aboutus_nav = [[[UINavigationController alloc] initWithRootViewController:aboutus_vc] autorelease]; 

NSArray vc_stack = [NSArray arrayWithObjects:search_nav,search_bookmarks_nav,items_bookmarks_nav,aboutus_vc,nil]; 

tabBarController.viewControllers = vc_stack; 

[self.window addSubview:tabBarController.view]; 

SearchViewControllerを基本的に選択された行についての詳細を表示し、選択した行とのUITableViewに結果を示す検索フォームです。ユーザーはUIImageViewを使用してビューコントローラーをプッシュしていくつかの写真を表示する "写真の表示"ボタンを押すこともできます。

写真ビューで作業しているとき、私はタブバーアプリケーションではうまくいかないような横向きの向きを扱わなければなりませんでした。この写真ビューコントローラが横向きの向きを扱えるようにするために、何をすべきかについてお手伝いできますか?

私は、このように横向きにできるようにするOR TabBarControllerをサブクラス化すると、この最後の解決策は、私のアプリは、Appleによって拒否される可能性があります任意のビューを作成するすべてのビューコントローラにYESを返すようにshouldAutorotateToInterfaceOrientation方法を行うことが言われてきました。ですから、私はちょっと何をするのかちょっと混乱しています...

あなたの助けになる前にThx!

ステファン

答えて

2

私は両方のオプションを使用しました。

  1. メイクshouldAutorotateToInterfaceOrientationメソッドがインスタンス化ごとにYESを返すように/ビューコントローラをサブクラス化:これが動作するためにあなたは、すべて単一のビューコントローラがYES返すようにそのshouldAutorotateToInterfaceOrientationメソッドを持っていることを確認する必要があります。 1つのオプションは、 ":UIViewController"のためのプロジェクト全体を検索するためのCMD + Shift + Fです。これは、UIViewControllerから継承しているすべてのヘッダーファイルのリストを表示するので、これに対応するすべての実装ファイルでshouldAutorotateToInterfaceOrientationをYESに設定しますヘッダー。 (この時々あなたがのUIViewControllerを継承するいくつかのクラスがあり、YESそこにshouldAutorotateToInterfaceOrientationを設定するために省略しているサードパーティのコードが含まれてmay'veため)

  2. サブクラスTabBarController:アップルのドキュメントはは「このクラスではないと言いますサブクラス化を意図しています。だから、私はこのオプションを使わないほうがいいでしょう。私は使っていますが、それはうまくいきますが、あなたは常にAppleによって拒否されている可能性があります。 (そうでないかもしれない最初の時間が、任意のアップグレードに関する)

とにかく、私はタブバーが画面上に多くのスペースを取っているため、Appleはランドスケープモードで表示されるようにタブバーアプリケーションを奨励していませんと思います。したがって、アプリケーションのアーキテクチャを検討して、タブバーコントローラーが本当に必要かどうかを確認したり、iPhone上のTwitterアプリケーションのような独自のtabbarcontrollerコントロールを作成したりする方がよいでしょう。この方法では、lanscapeのときにタブバーの高さを減らすことができます。

+0

正常に動作します。どうも – Steve

3

そのは非常に単純なあなただけ行う必要があります。 - あなたの一人ひとりのViewControllerのため

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

を。(あなたはiOS5をで開発している場合は、デフォルトで有効になっている)サブビューコントローラのそれぞれに回転を可能にすることに加えて

1

、あなたが画面全体を引き継ぐようにしたい場合のようなものを実行します。

UIInterfaceOrientation toOrientation = self.interfaceOrientation; 

if (self.tabBarController.view.subviews.count >= 2) 
    { 
UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0]; 
UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 


if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) { 
    transView.frame = CGRectMake(0, 0, 568, 320); 
    self.portraitView.hidden = YES; 
    self.landscapeView.hidden = NO; 
    tabBar.hidden = TRUE; 
    self.wantsFullScreenLayout = YES; 
} 
else 
{ 
    //Designing to accomodate the largest possible screen on an iPhone. The structs and springs should be setup so that the view will remain consistent from portrait to landscape and back to portrait. 
    transView.frame = CGRectMake(0, 0, 320, 568); 
    tabBar.hidden = FALSE; 
    self.portraitView.hidden = NO; 
    self.landscapeView.hidden = YES; 
    self.wantsFullScreenLayout = NO; 
} 
    }` 

更新:

https://stackoverflow.com/a/13523577/1807026

関連する問題