オリエンテーションの変更が必要なだけTabBarViewControllerのいくつかのビューのいずれかのために
-
20-09-2019 - |
質問
私のアプリは、5つのタブでUITabBarControllerを持っています。 私は唯一の第五タブの向きを回転させるために必要な。 私は、サブクラス化することで景観に回転させるために、5つすべてを取得することができました UITabBarController
@implementation TabBarControllerRotate
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
if(tbc == nil){
//tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; ////// new //////
...
tbc.viewControllers =
[NSArray arrayWithObjects:viewController1, viewController2, viewController3
,viewController4,viewController5, nil];
<時間>
私はviewController1のための回転をオフにする必要がある今 - 4。 私はのために4つの* .Mファイルに次のコードを追加することで、これを行うしようとして失敗しました これらviewControllersます。
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
Rを成し遂げる方法について私に教えてください。 読書のためのおかげで、マーク
解決
私はこれを行うには、他の簡単な方法があると仮定し、私は最終的に解決策を得ました。 TabBarController第五のViewController、一つだけのタイトル それは向きを変更する必要があり、ある「MyNotes」
SubListViewController.mの内部TabBarControllerRotateオブジェクトが作成されます。
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; tbc.viewControllers = [NSArray arrayWithObjects:viewController1 , viewController2, viewController3, viewController4, viewController5, nil tbc.delegate = self;
TabBarControllerサブクラスUITabBarControllerとBOOLプロパティが含まれ bMyNotesに名前を付けます。
SubListViewControllerがUITabBarControllerDelegateである
ビューがTabBarControllerに変更されるたびに、メッセージは、すなわち、送信されます - (無効)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(のUIViewController *)のViewController
したがってSubListViewController.mは、このコードが含まれています。
#pragma mark UITabBarControllerDelegate methods - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ BOOL b = (viewController.title == @"MyNotes"); [tbc setBMyNotesTab:b]; //NSLog(@"MyNotesTab == %d", [tbc bMyNotesTab]); }
次にTabBarControllerRotate.mは含まれています:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { //NSLog(@"bMyNotesTab is: %d",self.bMyNotesTab); return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationPortrait ) && self.bMyNotesTab );
}